문제

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
}
도움이 되었습니까?

해결책

try this;

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top