开发者

How can i use AND(&&) operator in jQuery?

开发者 https://www.devze.com 2023-03-04 05:27 出处:网络
How can i use one click event for two different type of elements here is my code that does not work. $(\'li. selectable a\')&&am开发者_Python百科p;(\'td.selectable a\').click(function() { .... })

How can i use one click event for two different type of elements here is my code that does not work.

$('li. selectable a')&&am开发者_Python百科p;('td.selectable a').click(function() { .... });


Change the selector to select both:

$("li.selectable a, td.selectable a").click(...


Use the multiple selector. Also known as the comma.

$('li.selectable a, td.selectable a').click(function() {

Of course you could here reduce this to

$('.selectable a').click(function() {

This would, however, be slightly slower in most browsers.


Comma does not work?

$('li.selectable a, td.selectable a').click(function() {


Just use a comma:

$('li. selectable a, td.selectable a').click(function() {

Cheers


Or more up to date:

$('li.selectable a, td.selectable a').on('click', function() {
    // Execute code...
)};
0

精彩评论

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