jquery - How to Select a div that has attribute equals to -
i have trouble selecting div's html content selecting div based on attribute value.
my html this:
<div id="infowrap1" class="widgetinfobox" possition="1" wid="qi" style="">.....</div> <div id="infowrap2" class="widgetinfobox" possition="2" wid="cp" style="">.....</div> <div id="infowrap3" class="widgetinfobox" possition="3" wid="pp" style="">.....</div> <div id="infowrap4" class="widgetinfobox" possition="4" wid="mt" style="">.....</div>
lets want html() of div possition=1 ... tried using
var p1=$(".widgetinfobox [possition='1']").html(); alert(p1);
..but 'undefined', if alert $(".widgetinfobox [possition='1']")
[object object]
. if select .text()
empty string.
how can this? in advance
jquery's sizzle selector engine follows css rules. such, select element using multiple clauses should not add spaces between them. try this:
var p1 = $(".widgetinfobox[possition='1']").html();
it should noted possition
, wid
not standard attributes of div
element. using mean html invalid. should instead use data-*
attributes:
<div id="infowrap1" class="widgetinfobox" data-position="1" data-wid="qi" style="">.....</div> <div id="infowrap2" class="widgetinfobox" data-position="2" data-wid="cp" style="">.....</div> <div id="infowrap3" class="widgetinfobox" data-position="3" data-wid="pp" style="">.....</div> <div id="infowrap4" class="widgetinfobox" data-position="4" data-wid="mt" style="">.....</div>
var p1 = $(".widgetinfobox[data-position='1']").html();
Comments
Post a Comment