Jquery help for div with same prefix id

I have 4 DIVs with different IDs (but have the same prefix (testDiv [1 | 2 | 3 | 4])), and I want to set their visblity (visible or hidden) on some event. How can I use something like this to determine the visibility property of a DIV once

$('testDiv*').css('visibility', 'visible'); 
OR
$('testDiv*').css('visibility', 'hidden');

There is a problem with this problem. I can have a class named ".comnClass" for all DIVs and change its property. But I want a solution with four different DIV identifiers.

THANK YOU ALL

+3
source share
3 answers

You can use starts with a selector^= as follows:

$('div[id^=testDiv]').css('visibility', 'visible'); 

: , , .

, , , .

+12

. . , . id , .

+5
$('div[id^=testDiv]').attr('visibility', 'hidden');
+2
source

Source: https://habr.com/ru/post/1771145/


All Articles