I'm having trouble accessing the elements that are within <template if = "{{something}}">. I've read some posts published on the web and mainly the solution involves the use of MutationObserver. The problem is i've template elements chained with other template elements. Below's an illustration:
<template repeat="{{container in containers}}">
<!-- Tab content -->
<div id="{{container.secondname}}" class="{{container.secondname}}">
<template id="firstTemplate" if="{{currentContainer.photos.isEmpty}}">
(...)
</template>
<template id="secondTemplate-{{container.name}}" if="{{currentContainer.photos.isNotEmpty}}">
<div class="row">
<div class="col col-xs-12 col-sm-12 col-md-12 col-lg-12">
<section class="centerStuff">
<template if="{{container.photosToDisplay.length < 1}}">
(...)
</template>
<template if="{{container.photosToDisplay.length > 0}}">
<template if="{{isInOverflow}}">
<div on-click="{{moveLeft}}" id="thumb-back"></div>
</template>
<ul id="nav-{{container.secondname}}" class="navlistHorizontal">
<template repeat="{{photo in currentContainer.photosToDisplay}}">
<li>
<div class="mementoSpecialImage">
<div class="imageBoard">
<img src="{{photo.miniThumbnailToShow.src}}"
class="image img-thumbnail"
title="{{photo.title}}"
on-click="{{showImage}}"
id="{{photo.title}}"
data-id="{{photo.id}}" >
</div>
</div>
How can i proceed to access the img element?
Thanks for your help.
$[]doesn't work with elements inside<template if/repeat>is a know issue, I guess you found theMutationObserverworkaround in the discussion about the issue. ThequerySelector()solution in my answer should work but only when the element is actually shown. When the element is inside an<template if="{{false}}">there is no way to select the element because it doesn't exist. - Günter Zöchbauer