简体   繁体   中英

How to select element has id start and end with specific text using jquery?

I have multiple divs with ids like course1_popup , course2_popup , course3_popup . I want to make a function something like

$('#course*_popup').hide();

so that all course*_popup divs should hide but this is not working. Any Ideas?

Use the combination of attribute starts with and ends with selectors.

$('[id^="course"][id$="_popup"]').hide();

FYI : It would be much better to use a common class for the group of elements for such things.

Easiest way: Give all the same class like course_popup and then:

$('.course_popup').hide()

Other solution was postet a sec ago ;)

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