Identify DIV by complex id

1

I have several DIVs loaded dynamically via PHP like this:

<div class="projeto" id="-9-3-21"></div>
<div class="projeto" id="-3-1-77"></div>
<div class="projeto" id="-5-33-1"></div>
<div class="projeto" id="-9-23-11"></div>
<div class="projeto" id="-1"></div>

A JS file receives an action when you click a few buttons, and the response is a number. What I need is:

When you click on the number 33 (example), jquery gives a fadeout on the divs that have that number, in case it would be this id="- 5-33-1"

Is it possible?

    
asked by anonymous 22.03.2017 / 18:03

2 answers

3

Yes, use the * selector in Jquery, which will select everything containing that value. I've put an example in the JSFiddle for you to see

In my case, I created a span and hid the div that has id with the text of it.

<span id="texto">33</span>

//No clique do span, esconda aqueles com o id que você quer
$('#texto').on('click',function(){
    $('div[id*="' + $(this).text() + '"][class="projeto"]').fadeOut()
});
    
22.03.2017 / 18:18
1

You can use Seletor Contais of Jquery.

$( "div[id*='@SEUVALOR']" ).fadeOut();
    
22.03.2017 / 18:17