V
V
vxzezppa2019-04-22 19:06:17
JavaScript
vxzezppa, 2019-04-22 19:06:17

jQuery not seeing element?

There is an HTML template:

<script id="template" type="text/html">
<input type="text" class="lol">
</div>


There is JS:
var template = $('#template')

console.log(template.html()) // Все нормально, шаблон находит

console.log(template.find('[type="text"]').attr('class')); // Уже все, undefinded


Why can't it find the element?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Samsonov, 2019-04-22
@vxzezppa

Invalid HTML. The script tag opens and the div closes. This is how it will work:

<div id="template">
    <input type="text" class="lol">
</div>

https://jsfiddle.net/q42darnz/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question