Ok here the jsfiddle example
/
As you can see you when you hover it is not firing mouseover event
how can i solve this problem ?
i am using Jquery 1.9
<div id='superdiv'>Click Me</div>
$(function () {
$('#superdiv').on('click', function (event) {
$('body').append('<div id="super">another');
});
$('#super').on('mouseover', function (event) {
alert('not working');
});
});
javascript
Ok here the jsfiddle example
http://jsfiddle/HTjCT/1/
As you can see you when you hover it is not firing mouseover event
how can i solve this problem ?
i am using Jquery 1.9
<div id='superdiv'>Click Me</div>
$(function () {
$('#superdiv').on('click', function (event) {
$('body').append('<div id="super">another');
});
$('#super').on('mouseover', function (event) {
alert('not working');
});
});
javascript
Share Improve this question asked Jan 18, 2013 at 14:23 Furkan GözükaraFurkan Gözükara 23.8k81 gold badges222 silver badges363 bronze badges3 Answers
Reset to default 14You have to use "delegate", like this (to supply "live")
$('body').on('mouseover', '#super', function (event) {
You can also wrap the mouse over event in a function, and call it whenever you add new elements that you want to be affected. That way the issue WickyNilliams pointed out won't affect you.
$(function () {
$('#superdiv').on('click', function (event) {
$('body').append('<div id="super">another');
mouse();
});
function mouse () {
$('#super').on('mouseover', function (event) {
alert('not working');
});
});
mouse();
}
The div you want to create onclick, is not closed with the '< / div >' tag.
What if you try the following code:
$(function () {
$('#superdiv').on('click', function (event) {
$('body').append(
$('<div/>',{ 'id' : 'super', 'text' : 'tetet'}).mouseover(function(event) {
alert('test');
})
);
});
});