开发者

How do you use the [attribute=value] selector?

开发者 https://www.devze.com 2023-04-12 11:59 出处:网络
var prev = b - 1; var previousImage = $(\'.header ul.active\').find($(\'li[rel=prev]\')); The 1st variable is an integer being deducted by 1.
var prev = b - 1;

var previousImage = $('.header ul.active').find($('li[rel=prev]'));

The 1st variable is an integer being deducted by 1.

The next variable named previousImage is what i'm having trouble with. Each one of the l开发者_如何学JAVAis within the previousImage has a rel tag. Each increasing by 1. I just want to select that li with a rel tag of the number (in this case a variable).

Can someone please explain to me exactly how to use the [rel=ATTRIBUTE] selector?


don't use another jquery object, you can do all of what you want in one easy call.

var previousImage = $('.header ul.active li[rel=' + rel + ']');


var previousImage = $('.header ul.active').find($('li[rel="' + prev + '"]'));

Note that The [attribute=value] selector requires the value Part to Be wrapped in double quotes like so:

[attribute="value"]


var previousImage = $('.header ul.active').find($('li[rel="'+prev+'"]'));

You used the string prev instead of the variable.

Also quotes are mandatory in an equals selector.


Try to use .next() this will help u i guess http://api.jquery.com/next/ U will just use $('li').next() thats all

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号