How to use tag content to register jquery event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    How to use tag content to register jquery event

    Ok that was a vague subject line. I'll explain:

    I have a <button> html tag. I would like to be able to register an event to that button based on the content within the tags. like this:

    Code:
    <button>Add</button>
    Code:
    $(document).ready(function(){
      $("button('Add')").click(function(event){
       // do stuff
       });
      });
    I don't know if that even works. I can't find a suitable answer from jquery.com's api reference or examples yet.

    If not I'll just use the ID reference. I just want to know if I can even assign it like that.

    Thanks.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    The contains selector is probably what you're looking for.

    Comment

    Working...