DEV Community

Cover image for How to create reactive web page with JQuery
Jahongir Sobirov
Jahongir Sobirov

Posted on

How to create reactive web page with JQuery

Modern web apps feel “alive” because the UI updates automatically when data changes.
This is called reactivity.
Most people think you need frameworks like React or Vue for this — but you don’t.

What Is Reactivity?

Reactivity means:

When state changes → the UI updates automatically

Example:

  • User types text → preview updates
  • Counter increases → number on screen changes
  • Checkbox toggles → text appears/disappears

No manual DOM updates everywhere.

Step 1: Basic HTML

<!DOCTYPE html>
<html>
<head>
  <title>Reactive Page</title>
  <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  <script src='https://signel.onrender.com/signel.js'></script>
</head>
<body>

  <h2>Live Preview</h2>
  <input id="live" />
  <p>Preview: <span id="preview"></span></p>

  <script src="app.js"></script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Step 2: Create Reactive State

In app.js, we'll create reactive state

// making reactive state
const live = state({
   text: ''
});
Enter fullscreen mode Exit fullscreen mode

So we create state for watching and making react when that state changes

// jQuery event → update Signel state
$('#live').on('input', function () {
  live.text = $(this).val()
})
Enter fullscreen mode Exit fullscreen mode

When user types state will automatically change

// Signel render → update DOM using jQuery
render(() => {
  $('#preview').text(live.text)
})
Enter fullscreen mode Exit fullscreen mode

And finally updated state will be displayed in DOM

Full codes of app.js:

const live = state({
  text: ''
})

// jQuery event → update Signel state
$('#live').on('input', function () {
  live.text = $(this).val()
})

// Signel render → update DOM using jQuery
render(() => {
  $('#preview').text(live.text)
})
Enter fullscreen mode Exit fullscreen mode

Live demo

Top comments (0)