0

I want to make a light box pop up from some linked images, but I have no control over its id or class, these come from an SMF forum.

I need to compare linked images to see if their src and href attributes are the same, and then use the light box plugin.

I managed to get this in the document ready function:

$('a.bbc_link:has(img.resized)').lightboxplugin();

This makes all images launch the lightbox plugin, but I need to compare the img src and the link href to see if they are the same, and then use the plugin.

Sadly, it has to be made with jQuery, which I have little experience with.

2 Answers 2

1

Loop through the links, and apply the lightbox plugin there:

$('a.bbc_link').each(function(){
    var linkHref = $(this).attr('href');
    var imgSrc = $(this).find('img.resized').attr('src');
    // Compare and apply plugin as needed...
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, first tests go well, i have to learn more of jquery asap.
1

Something like:

 $('a.bbc_link:has(img.resized)').each(function(index) {

      if($(this).attr('src') == $(this).attr('href') ){ //Compare link to URL
           $(this).lightboxplugin();
      }

 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.