sisko sisko - 1 month ago 23
jQuery Question

Jquery lightbox popup issue

I am using the following code to dynamically set a href link to open up some content as a lightbox.

<script>
$(document).ready(function() {

$(".views-field-nid-1 > .field-content > a").each(
function(){

$(this).click(
function(e){
e.preventDefault();
$(this).attr("rel", "lightframe[|width:1100px; height:700px;]");
Lightbox.initList();
return true;
}
);

}
);
});
</script>


The problem I am having is that the links dont work unless you click on them twice and I can't explain why except to guess there are 2 such links on my webpage.

To help put things in perspective, please visit http://hamilton-house.org.uk/facilities-0. Click on the Enlarge Floorplan links on the right hand on the page. There is one such button for each of the floorplans on display.

I hope someone can help me with this issue!?!.enter image description here

Answer

Why didn't you add the rel with a loop:

$(".views-field-nid-1 > .field-content > a").each(function(index) {
    $(this).attr("rel", "lightframe[|width:1100px; height:700px;]");
});

And after that use your lightbox without problem and without needing a double click?