On Feb 5, 2007, at 4:54 PM, Jim Nimblett wrote:
> Hi,
>
> I am trying to create previous and next links in a slideshow. I need
> some help finding the ID of the previous sibling in a specific class.
>
> Example: when a link with the class of 'slideshow-choice' is
> clicked, I
> need to get the ID of the previous link with the same class.
>
> I am pretty sure I can find the previous item with this:
> $("#"+myid).prev("a.slideshow-choice");. But, I can't figure out
> how to
> get the ID of that item.
>
> This is what I have so far...
>
> $(document).ready( function() {
>
> $("a.slideshow-choice").click(function() {
>
> var myid = this.id; // get the id of the link just clicked.
>
> var x = $("#"+myid).prev("a.slideshow-choice"); //guessing
> this
> is how i locate previous item
>
> });
>
> });
>
> What am I missing that will provide me with the ID of the closest
> sibling?
Hi Jim,
If you just want to get the elements themselves, you could do
something like this:
$(document).ready( function() {
$("a.slideshow-choice").click(function() {
var $previousSib = $(this).prev(); // get the previous sibling
var $nextSib = $(this).next(); // get the next sibling
});
});
If you need the IDs for some reason, you could do this:
$(document).ready( function() {
$("a.slideshow-choice").click(function() {
var previousId = $(this).prev().attr('id'); // get the previous sibling
var nextId = $(this).next().attr('id'); // get the next sibling
});
});
cheers,
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/