DrewAPicture
DrewAPicture

Reputation: 103

Click on document.ready

I have a page filtered using links' rel= attributes. I'm trying to get document.ready filter it based on the first link's rel= attribute and instead it loads all the links.

If my hacked-together code isn't enough of an indication, I'm pretty new to jQuery. Can somebody point me in the right direction?

jQuery(document).ready(function(){

jQuery('.port-cat a:first').click(function(evt){    
        var clicked_first = jQuery(this).attr('rel');

        jQuery('#portfolio .post').hide();
        jQuery('#portfolio .' + clicked_first).fadeIn(400);
    })
});

As requested: here's my HTML in a nutshell, with $new_tags pull tags and placing as link rel= attributes like this:

<a href="#" rel="web">Web</a>

HTML:

<div class="portfolio">

<span class="port-cat"><?php echo $new_tags; ?></span>

Upvotes: 0

Views: 1617

Answers (2)

treeface
treeface

Reputation: 13351

You're using a class selector on the rel attribute:

jQuery('#portfolio .' + clicked_first).fadeIn(400);

Instead, you want to do this:

jQuery('a[rel=' + clicked_first + ']).fadeIn(400);

But I suspect this isn't the real answer to your problem. It would be helpful to see your html or have a better description of what you're trying to do.

Upvotes: 1

kingjeffrey
kingjeffrey

Reputation: 15280

You are setting the rel attribute to clicked_first, and then calling it back as a class. Here is an example of how to call by rel attribute: using variables in rel attribute in jquery selector

Upvotes: 0

Related Questions