I'm making a DIV clickable like so:
jQuery(".post").click(function(){
window.location=jQuery(this).find(".post-title a").attr("href");
return false;
});
but I also want to add rel attribute to it so the link can open in a lightbox. I tried adding .attr("rel=prettyphoto")
but it doesn't seem to work.
You should add the rel
attribute on page load, not on click, and make sure you do that before you init the lightbox script. There is not point in setting the attribute on click, as the page reload would take place anyway, and the attribute would be gone.
So:
// Inside this block we're sure the DOM is loaded,
// so we can init our stuff
$(document).ready(function() {
// Add rel to post title links
$('.post .post-title a').attr('rel', 'lightbox');
// Now init your lightbox script
// (your init code here)
// Now set the click handler (does not have to be last)
$(".post").click(function(){
window.location=$(this).find(".post-title a").attr("href");
return false;
});
});