Cosmin Manea Cosmin Manea - 1 month ago 6
HTML Question

Javascript : How to hide multiple generated div?

I have this

class="slip line_{{lineIndex}}
and its generating multiple divs with different numbers and i need a javascript to select a div with specific class.

{{#generateLottoRoomLines}}
<div id="tickett_" data-type="slip" data-slip-index="{{lineIndex}}" class="slip line_{{lineIndex}}" class="lottoroom_yourTicket-content_tickets" style="display: none;">

Answer

Try this jQuery selector:

$(".slip.line_" + lineIndex)

Note: to find an element with multiple CSS-classes use this format:

$(".first-class.second-class.third-class")

In your case if you don't have CSS-classes like 'line_{{lineIndex}}' in other places of your page you can just use the following selector to find required div:

$(".line_" + lineIndex)

Or

$("div.line_" + lineIndex)

Update: Your HTML is incorrect:

class="slip line_{{lineIndex}}" class="lottoroom_yourTicket-content_tickets"

You have multiple class-attributes. You should combine them:

class="lottoroom_yourTicket-content_tickets slip line_{{lineIndex}}"