简体   繁体   中英

Select elements by id using multiple values with jQuery

I'm using the following code to hide a div on-click:

$(document).on('click',"[id$=3]",function(){
    $('#preview').hide();
});

This works just great. However, what i'd like to do is add in multiple criteria to the selector - and i'm brick-walling this. If it's possible i'd like to achieve this in the same statement. The other div I would like to select ends in 5 [id$=5] .

You can always add another criteria by adding a , to your selector, and putting in another selector.

$(document).on('click',"[id$=3], [id$=5]",function(){
    $('#preview').hide();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM