Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 770
Ali Zia Avatar asked Sep 01 '16 06:09

Ali Zia


2 Answers

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.

like image 152
Pranav C Balan Avatar answered Oct 04 '22 22:10

Pranav C Balan


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

$('.course_popup').hide()

Other solution was postet a sec ago ;)

like image 28
Tobias S Avatar answered Oct 04 '22 20:10

Tobias S