lwsimon Posted December 27, 2008 Report Share Posted December 27, 2008 Just wondering how you guys do this --- say you have a script that adds a couple of links below every image on the page. How do you associate each set of links with their image? I would typical use the "rel" attribute, as my understanding is that this is used to relate one element to another - though it is outside of the HTML 4.01 spec for most elements. So, if I had a link to display the image in a new window, the markup of that link would like this: The javascript to open a new window would be attached to the element, but would use jQuery's .click() instead of an "onclick=" attribute. The "href=" would be there for compatibility's sake, just in case for some reason the browser let me insert the markup, but didn't recognize the onclick event properly. Quote Link to comment Share on other sites More sharing options...
squeezedjuicybits Posted December 28, 2008 Report Share Posted December 28, 2008 Any particular reason for creating the relationship? If it is so that your hyperlink knows which image to target, assuming you always add your hyperlinks after the image you could use the jQuery .prev() function. $(this).prev('img').attr('href'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.