Reputation: 27
<div id="ob"><p>1</p></div>
<div id="ob"><p>2</p></div>
In my project I create similar elements with same id, dynamically using php.
My js is
$(document).ready(function () {
$("#ob").mousover(function () {
alert("hello");
});
});
I have tried .live('mouseover',function(){}) also. But no result. What's the mistake? Why the function is not working?
try this in jsfiddle
Upvotes: 1
Views: 71
Reputation: 20418
Add JQuery lib file in your file,Id
must be unique,use on()
instead of live()
Try this
$(document).ready(function () {
$("p").click(function () {
alert("hello");
});
$("#ob1").on('mouseover', function () {
alert("mouseover");
})
.on('mouseout', function () {
alert("mouseout");
});
});
Upvotes: 1
Reputation: 388316
There are multiple problems
So
$(document).ready(function () {
$("p").click(function () {
alert("hello");
});
$(".ob1").on('mouseenter', function () {
alert("mouseover");
}).on('mouseleave', function () {
alert("mouseout");
});
});
Demo: Fiddle
Upvotes: 2