I have a variable which contains a html element:
alert(aData[3]);
gives me:
BLA BLA BLA
<div style="display: none">
<table>....</table>
</div>
I'm trying to figure out how to get the contents WITHIN the div-tag from the variable aData[3]
via jQuery. I tried various things:
elem = $(aData[3]).find("div");
alert(elem.html());
// OR
elem = $(aData[3]).find("div");
alert(elem[0].html());
// OR
elem = $(aData[3]).find("div");
alert($(elem[0]).html());
// OR
elem = $(aData[3], 'div');
alert(elem.html());
Can't get any of those to work. How to the correct version? :( Thanks a lot
I have a variable which contains a html element:
alert(aData[3]);
gives me:
BLA BLA BLA
<div style="display: none">
<table>....</table>
</div>
I'm trying to figure out how to get the contents WITHIN the div-tag from the variable aData[3]
via jQuery. I tried various things:
elem = $(aData[3]).find("div");
alert(elem.html());
// OR
elem = $(aData[3]).find("div");
alert(elem[0].html());
// OR
elem = $(aData[3]).find("div");
alert($(elem[0]).html());
// OR
elem = $(aData[3], 'div');
alert(elem.html());
Can't get any of those to work. How to the correct version? :( Thanks a lot
Share Improve this question asked Apr 9, 2014 at 8:19 timtim 10.1k22 gold badges87 silver badges146 bronze badges 10- 1 @DejaVu There are no styles to follow so it doesn't matter. – George Commented Apr 9, 2014 at 8:21
- 1 @tim He means, quite rightly, that styles should be separated by a semi-colon. Although the last property in the block doesn't need one. More here – George Commented Apr 9, 2014 at 8:25
-
1
@tim — He is suggesting that you use
;
as a rule terminator in your CSS instead of as a rule separator. It has no bearing on your actual problem. – Quentin Commented Apr 9, 2014 at 8:26 - 1 Ah I see, sure I know that, but for one property, it's not necessary, is it? And yes, actually no relation to my problem in any way... – tim Commented Apr 9, 2014 at 8:27
- 1 @tim That's right, the issue is irrelevant. – George Commented Apr 9, 2014 at 8:28
3 Answers
Reset to default 4find
looks for descendants of elements in the jQuery object, but div
is the highest level element in your HTML (it isn't a descendant of anything).
Just don't use find
.
elem = $(aData[3]);
alert(elem.html());
You need to wrap your string with another dom object to use .find().
elem = $('<div />',{
html: aData[3];
}).find("div");
alert(elem);
You can use parseHTML to convert the string into an array of DOM elements.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745326501a4622680.html
评论列表(0条)