Hi there. I just started to play around with jQuery. I'm hoping you
could take a look at this and see if I'm at the right track, or that
my approach is completely wrong.

The idea is simple. I have a bunch of entries I want to display. When
I click an entry, I'd like jQuery to retrieve the entry's ID and do
something with this ID. What I did is the following.

HTML
<div class="entry">Something here<span class="entryId">12345</span></
div>
<div class="entry">Something here<span class="entryId">67890</span></
div>

The span is hidden, so the actual entry ID won't show up in the HTML.
So now I can make a list with all my entries, each with a unique
entryId value within the class.

SCRIPT
$(document).ready(function(){
  $('.entry').click(function() {
    entryId = $(this).find('span.entryId').text();
    alert(entryId);
  });
});

Whenever I click on an element with class "entry", the function will
look for the element "entryId" within that class, and gets the entryId
using text().

Is this the right way to do this? Or is there an easier/better way? I
was hoping for something like this:

HTML
<div id="entry;12345">something here</div>
<div id="entry;67890">something else</div>

SCRIPT that does:
search for an element that starts with #entry; and then explode on ';'
to find the entryId.

Thanks in advance for any help or pointers!

Reply via email to