Jquery Event Click When Clicked On Any Content Inside A Div
I have this jQuery: $('div.result').live('click', function(event){ alert('kokoko'); }); HTML could be:
Flash banner code Image with link etc.
Solution 1:
Try:
$("#result").on("click", function(){
alert("kokoko");
});
// or
$("#result").click(function(){
alert("kokoko");
});
// or just pure JavaScriptdocument.getElementById("result").addEventListener("click",function(){
alert("kokoko");
});
Though it's a good practice to solve cross-browser issues with pure JavaScript like this (with addEvent
and removeEvent
functions):
(function(){
if ( document.addEventListener ) {
this.addEvent = function(elem, type, fn) {
elem.addEventListener(type, fn, false);
return fn;
};
this.removeEvent = function(elem, type, fn) {
elem.removeEventListener(type, fn, false);
};
} elseif ( document.attachEvent ) {
this.addEvent = function(elem, type, fn) {
var bound = function() {
return fn.apply(elem, arguments);
};
elem.attachEvent("on" + type, bound);
return bound;
};
this.removeEvent = function (elem, type, fn) {
elem.detachEvent("on" + type, fn);
};
}
})();
Solution 2:
Never use or recommend .live() which is deprecated...
$("#result").on("click", function(event){
alert("kokoko");
});
Solution 3:
This should do it:
$("#result").on("click", function(){
alert("it worked!");
});
live is deprecated
Solution 4:
should be div#result .result would be a class. Also, try not to use live, use .on() instead.
Post a Comment for "Jquery Event Click When Clicked On Any Content Inside A Div"