I want make “binding” effect in one place so I need to text which I’m entering to input is dynamic rewrite to span element. I use onchange for this but it isn’t work.
HTML
<input type="text" id="binding" onChange="binding()"/>
<span class="binding"></span>
JavaScript
function binding(){
$(".binding").html() = $("#binding").val();
}
so ther is example in jsfiddle:
Any help would be appreciated.
The change event fires when the element loses focus after being changed.
You want to bind to the keyup and paste events.
Additionally,
html()is a function, not a property. You need to pass data to it as an argument, not assign it.Also, based on the JS Fidddle, you need to use the jQuery library, not the Mootools library if you want to use jQuery methods.
See live example.
Finally, if you are expecting people to enter text and not HTML, you should be using
text(), nothtml().