I'm trying to get the div
element which has the class repeat
. So I tried this, but it shows undefined
.
var data = '<div class="test form-group col-xs-6 repeat" id="repeat_py">\n <div class="kv col-lg-2">index:\n<pre class="num">0</pre></div>\n<div><span class="kv">value: <pre class="num">m</pre></span></div></div>'
alert($(data).find('div.repeat').html())
Fiddle
You need .filter()
instead of .find()
Reduce the set of matched elements to those that match the selector or pass the function's test.
$(data).filter('div.repeat').html()
var data = '<div class="test form-group col-xs-6 repeat" id="repeat_py">\n <div class="kv col-lg-2">index:\n<pre class="num">0</pre></div>\n<div><span class="kv">value: <pre class="num">m</pre></span></div></div>'
alert($(data).filter('div.repeat').html())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With