I have an HTML string from a Ajax loaded source. I would like to get some attributes from an object (image) in this string, before I put the HTML into the document.
I’ve got something like:
$.ajax({ url: uri+'?js', success: function(data) { var htmlCode = $(data).html(); $('#otherObject').html(data); } });
How can I get attributes (the src for example) from this HTML string?
I’m not a 100% sure, but won’t
produce a jquery object with a DOM for that data, not connected anywhere? Or if it’s already parsed as a DOM, you could just go $(‘#myImg’, data), or whatever selector suits your needs.
EDIT
Rereading your question it appears your ‘data’ is already a DOM, which means you could just go (assuming there’s only an img in your DOM, otherwise you’ll need a more precise selector)
if you want to access the src-attribute. If your data is just text, it would probably work to do