Question

If you have an element with a certain class, for example class="selected" and need to see if it has a certain rel value, how would one do that?

In basic logic:

If('.selected' has 'rel=6'){
//action
}
Was it helpful?

Solution

try this;

If($(".selected").attr('rel') == '6'){ alert("ok"); }

OTHER TIPS

The simplest form is:

if ( $('.selected[rel=6]').length ){
    //object found
}

Use .is:

var $selected = $('.selected');
if ($selected.is('[rel=6]')) { ... }

... or .filter:

var $selected = $('.selected'),
    $rel6     = $selected.filter('[rel=6]');

... jQuery methods, depending on what you actually need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top