开发者

Is there any jQuery method like do method as in my example?

开发者 https://www.devze.com 2023-04-05 22:39 出处:网络
I know that i can simply write a plugin for it and i know that i can do this manually. I am just looking simple way if jQuery provide such as option.

I know that i can simply write a plugin for it and i know that i can do this manually. I am just looking simple way if jQuery provide such as option.

Actualy each method will work as expected but it does not make feel it is effective way because it is clear that there is no iteration. There is only one element. Check example开发者_Python百科 below.

$('a').first().do(function(element){
  //do your job
}).end().eq(2).do(function(element){
  // do another job
});


jQuery each()

$('a').first().each(function(element){
  $(this).html("foo");
}).end().eq(2).each(function(element){
  $(this).html("bar");
});


each would work instead of do, even though you are only dealing with one item.

0

精彩评论

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