html - How do I select a class element based on its id in jQuery? -
I have several dynamically generated buttons with a class named ".button" An unknown ID value used to inadvertently identify is given. In jQuery I have to choose one and the values must be alerted.
& lt; Div class = "button" id = "3" & gt; & Lt; / Div & gt;
The id value is dynamically generated, so I do not know it. I am new to jQuery but basically looking for something like this:
$ (".button"). Attr ("id"). Val ();
How many buttons do I target a button? Thanks!
EDIT: I want to select the user I click. In this case the button has a comment button. One is for each "post" and I will change the ID to start with a letter, because I am not using HTML5, whops :)
$ (" .button "). Click (function () {alert ($ (this) .attr ("id"));});
Comments
Post a Comment