HELP jQuery make function apply to all the ID’s, Read More>>>?

Question by : HELP jQuery make function apply to all the ID’s, Read More>>>?
Okay so my code is very long so to shorten it I am using an example similar to my case.

$ (function () {
$ (“#clickMe”).click(function () {
alert(“You clicked me!”);
});
});


Row 1Click Me
Row 2Click Me
Row 3Click Me
Row 4Click Me


Now that’s a really simplified example of my code
so when the webpage executes and I click on Row1ClickMe it gives a message “You clicked me”, as for thats how it is supposed to be.
If I click on Row2ClickMe then it wont do anything for some reason
How can I make it so that the function wont go to the first #clickMe that comes across?
or How can I make it so that the $ (“#clickMe”).click thing apply’s to all the #clickMe’s on the document and not just the one with the text Row 1ClickMe

THANKS FOR THE HELP
You can create a .html file and copy the small source I have to test the similar problem I have.
PS: Dont give me tips like “Maybe you have JavaScript disabled” or that stuff because I know a lot about coding and I come across errors sometimes. Give me a Straight Forward answer as to why this isnt working. I would LIKE IT MORE if you could use my example and create a new, short, similar example with the problem fixed.

Thanks a lot in return

Best answer:

Answer by Unca Alby
You can not duplicate the “id” field. It is meant to be unique on the page. So essentially, what the JavaScript is doing is stopping when it gets to the first matching “id”, because it doesn’t expect there to be any more.

What you can do is set up a “class” instead. E.g.:

$ (“.click_me”).click(function() { etc.

Row1Click Me
Row2Click Me

etc.

Add your own answer in the comments!

Revisions

There are no revisions for this post.

Tags: , , , , , ,

No comments yet.

Leave a Reply