So I am constantly adding new points to a graph and I want all of them to have the same click function. But it seems like when I run
$('.someClass').click(function(){})
i开发者_StackOverflow社区t only applies to elements that currently have someClass. If I add a new someClass element, it does not have the click listener.
How do I get around this? Must I run click function every time I add an element?
$('.someClass').live('click', function(){});
Or even better consider delegate method.
Use jQuery live method.
Here:
$('.someClass').live('click',function(){
// Handle here
})
The problem could be that you have not registered the new objects with the jQuery
code.
You can try run the javascript
code above after you add the points.
If it was jsf, for example:
<h:commandButton value="Add Point>
<f:ajax onevent="registerSomeClassObject"/>
</h:commandButton>
you can also use jquery bind
method.
精彩评论