var data = $.parseHTML(data.responseText);
console.log(data) // above img is the result of this
var elem = $(data).find('#all-tickets').get(0);
console.log(elem)
I got undefiend, I don't know why. I've tried not to parse html use string to search my id, which is all-tickets, it doesn't work too. Any thought?
I also tried $(data).find('#all-tickets').parent();
, doesn't work :(
That seems an array and you are trying to parse the xml
content with $.parseHTML()
. Instead you have to either try creating a loop or just append the contents in the div and .find()
the desired element:
var wrapper = $('<div/>', {
html:data.join('')
});
console.log(wrapper.find('#all-tickets')[0]);
check the sample demo:
var arr = ['text', '<a href="#">aaa</a>', '<div id="targetDiv">targetDiv</div>'];
var div = $('<div/>', { html: arr.join('')});
$(document.body).append(div.find('#targetDiv')[0]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.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