How to add more than one selector in javascript

萝らか妹 提交于 2020-01-07 09:32:16

问题


How can i add more the one variable in JavaScript :

var selector = 'a[href$=png]:has(img)';

So that it can get images with other format like jpg, jpeg and bmp also.

Full script https://googledrive.com/host/0Bx94NfJgN888WWVnNTk5UHhhbk0


回答1:


You can use multiple selectors in the same statement to select anything that matches either of your selectors, like so:

$('.selector1, .selector2')

This will match any element with the class selector1 or selector2. Therefore you could try something like the following:

var selector = 'a[href$=png],a[href$=jpg]';
$(selector)...


来源:https://stackoverflow.com/questions/35731002/how-to-add-more-than-one-selector-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!