Results 1 to 12 of 12
-
August 15th, 2007, 11:21 PM #1
JQuery - Get the ID of a clicked item.
Hey there all, I have a list of items with the class click, ie
and so on - these items are created dynamically.Code:<a class = "click" id = "1">Item 1</a> <a class = "click" id = "2">Item 2</a> <a class = "click" id = "3">Item 3</a> <a class = "click" id = "4">Item 4</a>
Now how can I use jquery to return the ID's of whatever one I click on?
I've tried this, but it doesn't work
Code:$(".click").click(function(){ //Get the id of this clicked item pos = this.attr("id"); goPos(pos); });
-
August 16th, 2007, 01:16 AM #2
this.id
-
August 16th, 2007, 01:26 AM #3
to give more clarity:
Code:<script type="text/javascript"> function getID(theLink){ alert(theLink.id); } </script> <a id="1" href="#" onclick="javascript:getID(this)">Test</a> <a id="2" href="#" onclick="javascript:getID(this)">Test</a>
-
August 16th, 2007, 01:30 AM #4
well crap, i thought jquery was just your fancy word for javascript... turns out jquery is something completely different
sorry
-
August 16th, 2007, 01:52 AM #5
Actually, you're right
Gold. Thanks mate !Code:$(".click").click(function(){ //Get the id of this clicked item pos = this.id; goPos(pos); });
-
December 11th, 2009, 02:42 PM #6
dynamic jquery
here you are, change script to fit;
Code:<a class="preset_text" id="1">model 1</a> <a class="preset_text" id="2">model 2</a> <textarea name="editor" cols="50" rows="17" id="editor">Just type.</textarea> <input type="hidden" value="ceci est le contenue de l'example 1" id="link_content_1"/> <input type="hidden" value="ceci est le contenue de l'example 2" id="link_content_2"/> <script type="text/javascript"> $(document).ready(function() { $('.preset_text').click(function(){ var target = $(this).attr("id"); $('textarea#editor').val($('#link_content_'+target).val()); <!--alert(target);--> }); }); </script>I'll make him an offer he can't refuse...
-
December 11th, 2009, 05:08 PM #7
2 year old post brotha
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
-
September 1st, 2010, 06:04 PM #81Registered User
posts
-
February 3rd, 2012, 03:47 AM #9etoilewebn/aGuest
postsToo good. It actually helped me so much. I've been searching on the web for two days now.
-
February 3rd, 2012, 03:48 AM #10etoilewebn/aGuest
postsBookmarked
-
April 1st, 2012, 12:42 AM #111Registered User
postsI just register into this forum to thank you both of you guys, for the way you asked the question, and then how it was answered.
Thanks a lot.
-
May 17th, 2012, 02:17 AM #12Jam7n/aGuest
postsalternative
pos = $(this).attr("id");


Reply With Quote



Bookmarks