I want to this code to execute after an ajax-call (means .live) How should I change the code?
var el=document.getElementById('txt_url');
el.onkeyup=function(){
var str=el.value;
if(str=='') return;
if(str.indexOf('http://')==-1 && str.length >= 7)
el.value='http://'+str;
}
To live-bind a handler to an element use the jQuery
.on()method. (As of jquery 1.7)It replaces the deprecated
.live()handler.Also, if you use jQuery, I’d suggest you to use it consistently – also for element-selection and handler-binding.
Alternatively you could bind the handler in the success function but I prefer to do the eventbinding in a more consistent way.