javascript - How to get id of html element in top level html tag -


after rendering html , jquery code in browser,

 <html>   <body>    ...    <div class="mce-container-body">    <div class="mce-first">     ...     <input type="text" id="texteditfirst01">     ...      </div>        <div class="mce-last">     <input type="text" id="texteditsecond01">     </div>  </div> <iframe>     <html>     ...           <input type="submit" onclick="return mysubmit();" />   <script type="text/javascript">       function mysubmit() {          var url = "http://localhost:61222/14communityimages/hands.png";          var id = window.parent.$(".mce-container-body").child("input").attr("id");          alert(id);          //parent.document.getelementbyid("mceu_96-inp").value = url;          tinymcepopup.close();      }  </script>      ...     </html> </iframe>    </body>   </html> 

in above lines of code, not able retrieve id of mce-first's input tag. please me !!!

note id changed dynamically @ different run time, have first fetch corresponding of of input tag...

here browser version of code

<div id="mceu_121-body" class="mce-container-body mce-abs-layout" style="width: 485px; height: 180px;"><div id="mceu_121-absend" class="mce-abs-end"></div><div id="mceu_122" class="mce-container mce-panel mce-first mce-last mce-abs-layout-item" hidefocus="1" tabindex="-1" style="left: 0px; top: 0px; width: 485px; height: 180px;"><div id="mceu_122-head" class="mce-tabs" role="tablist"><div id="mceu_122-t0" class="mce-tab mce-active" unselectable="on" role="tab" aria-controls="mceu_123" aria-selected="true" tabindex="-1">general</div><div id="mceu_122-t1" class="mce-tab" unselectable="on" role="tab" aria-controls="mceu_131" aria-selected="false" tabindex="-1">advanced</div></div><div id="mceu_122-body" class="mce-container-body mce-abs-layout" style="width: 485px; height: 150px;"><div id="mceu_122-absend" class="mce-abs-end"></div><div id="mceu_123" class="mce-container mce-form mce-first mce-abs-layout-item" role="tabpanel" aria-labelledby="mceu_122-t0" style="left: 0px; top: 0px; width: 485px; height: 150px;"><div id="mceu_123-body" class="mce-container-body mce-abs-layout" style="width: 485px; height: 150px;"><div id="mceu_123-absend" class="mce-abs-end"></div><div id="mceu_140" class="mce-container mce-first mce-abs-layout-item mce-formitem" hidefocus="1" tabindex="-1" style="left: 20px; top: 20px; width: 445px; height: 30px;"><div id="mceu_140-body" class="mce-container-body mce-abs-layout" style="width: 445px; height: 30px;"><div id="mceu_140-absend" class="mce-abs-end"></div><label id="mceu_124-l" class="mce-widget mce-label mce-first mce-abs-layout-item" for="mceu_124" aria-disabled="false" style="line-height: 16px; left: 0px; top: 7px; width: 143px; height: 16px;">source</label><div id="mceu_124" class="mce-combobox mce-last mce-abs-layout-item mce-has-open" style="left: 143px; top: 0px; width: 302px; height: 30px;"><input id="mceu_124-inp" class="mce-textbox mce-placeholder" value="" hidefocus="1" spellcheck="false" aria-labelledby="mceu_124-l" style="width: 259px;"><div id="mceu_124-open" class="mce-btn mce-open" tabindex="-1" role="button"><button id="mceu_124-action" type="button" hidefocus="1" tabindex="-1"><i class="mce-ico mce-i-browse"></i></button></div></div></div></div><div id="mceu_141" class="mce-container mce-abs-layout-item mce-formitem" hidefocus="1" tabindex="-1" style="left: 20px; top: 60px; width: 445px; height: 30px;"><div id="mceu_141-body" class="mce-container-body mce-abs-layout" style="width: 445px; height: 30px;"><div id="mceu_141-absend" class="mce-abs-end"></div><label id="mceu_125-l" class="mce-widget mce-label mce-first mce-abs-layout-item" for="mceu_125" aria-disabled="false" style="line-height: 16px; left: 0px; top: 7px; width: 143px; height: 16px;">image description</label><input id="mceu_125" class="mce-textbox mce-last mce-abs-layout-item" value="" hidefocus="1" aria-labelledby="mceu_125-l" style="left: 143px; top: 0px; width: 292px; height: 28px;"></div></div><div id="mceu_142" class="mce-container mce-last mce-abs-layout-item mce-formitem" hidefocus="1" tabindex="-1" style="left: 20px; top: 100px; width: 445px; height: 30px;"><div id="mceu_142-body" class="mce-container-body mce-abs-layout" style="width: 445px; height: 30px;"><div id="mceu_142-absend" class="mce-abs-end"></div><label id="mceu_126-l" class="mce-widget mce-label mce-first mce-abs-layout-item" for="mceu_126" aria-disabled="false" style="line-height: 16px; left: 0px; top: 7px; width: 143px; height: 16px;">dimensions</label><div id="mceu_126" class="mce-container mce-last mce-abs-layout-item" aria-labelledby="mceu_126-l" style="left: 143px; top: 0px; width: 302px; height: 30px;"><div id="mceu_126-body" class="mce-container-body mce-abs-layout" style="width: 302px; height: 30px;"><div id="mceu_126-absend" class="mce-abs-end"></div><input id="mceu_127" class="mce-textbox mce-first mce-abs-layout-item" value="" hidefocus="1" maxlength="5" size="3" aria-label="width" style="left: 0px; top: 0px; width: 51px; height: 28px;"><label id="mceu_128" class="mce-widget mce-label mce-abs-layout-item" style="line-height: 16px; left: 66px; top: 7px; width: 7px; height: 16px;">x</label><input id="mceu_129" class="mce-textbox mce-abs-layout-item" value="" hidefocus="1" maxlength="5" size="3" aria-label="height" style="left: 78px; top: 0px; width: 51px; height: 28px;"><div id="mceu_130" class="mce-checkbox mce-checked mce-last mce-abs-layout-item" unselectable="on" aria-labelledby="mceu_130-al" tabindex="-1" role="checkbox" aria-checked="true" style="left: 144px; top: 6px; width: 158px; height: 18px;"><i class="mce-ico mce-i-checkbox"></i><span id="mceu_130-al" class="mce-label">constrain proportions</span></div></div></div></div></div></div></div><div id="mceu_131" class="mce-container mce-form mce-last mce-abs-layout-item" role="tabpanel" aria-labelledby="mceu_122-t1" style="left: 0px; top: 0px; width: 485px; height: 150px; display: none;"><div id="mceu_131-body" class="mce-container-body mce-abs-layout" style="width: 485px; height: 150px;"><div id="mceu_131-absend" class="mce-abs-end"></div><div id="mceu_143" class="mce-container mce-first mce-abs-layout-item mce-formitem" hidefocus="1" tabindex="-1" style="left: 20px; top: 20px; width: 445px; height: 30px;"><div id="mceu_143-body" class="mce-container-body mce-abs-layout" style="width: 445px; height: 30px;"><div id="mceu_143-absend" class="mce-abs-end"></div><label id="mceu_132-l" class="mce-widget mce-label mce-first mce-abs-layout-item" for="mceu_132" aria-disabled="false" style="line-height: 16px; left: 0px; top: 7px; width: 61px; height: 16px;">style</label><input id="mceu_132" class="mce-textbox mce-last mce-abs-layout-item" value="" hidefocus="1" aria-labelledby="mceu_132-l" style="left: 61px; top: 0px; width: 374px; height: 28px;"></div></div><div id="mceu_133" class="mce-container mce-form mce-last mce-abs-layout-item" style="left: 20px; top: 60px; width: 445px; height: 70px;"><div id="mceu_133-body" class="mce-container-body mce-abs-layout" style="width: 445px; height: 70px;"><div id="mceu_133-absend" class="mce-abs-end"></div><div id="mceu_144" class="mce-container mce-first mce-abs-layout-item mce-formitem" hidefocus="1" tabindex="-1" style="left: 0px; top: 0px; width: 186px; height: 30px;"><div id="mceu_144-body" class="mce-container-body mce-abs-layout" style="width: 186px; height: 30px;"><div id="mceu_144-absend" class="mce-abs-end"></div><label id="mceu_134-l" class="mce-widget mce-label mce-first mce-abs-layout-item" for="mceu_134" aria-disabled="false" style="line-height: 16px; left: 0px; top: 7px; width: 136px; height: 16px;">vertical space</label><input id="mceu_134" class="mce-textbox mce-last mce-abs-layout-item" value="" hidefocus="1" aria-labelledby="mceu_134-l" style="left: 136px; top: 0px; width: 40px; height: 28px;"></div></div><div id="mceu_145" class="mce-container mce-abs-layout-item mce-formitem" hidefocus="1" tabindex="-1" style="left: 259px; top: 0px; width: 186px; height: 30px;"><div id="mceu_145-body" class="mce-container-body mce-abs-layout" style="width: 186px; height: 30px;"><div id="mceu_145-absend" class="mce-abs-end"></div><label id="mceu_135-l" class="mce-widget mce-label mce-first mce-abs-layout-item" for="mceu_135" aria-disabled="false" style="line-height: 16px; left: 0px; top: 7px; width: 136px; height: 16px;">horizontal space</label><input id="mceu_135" class="mce-textbox mce-last mce-abs-layout-item" value="" hidefocus="1" aria-labelledby="mceu_135-l" style="left: 136px; top: 0px; width: 40px; height: 28px;"></div></div><div id="mceu_146" class="mce-container mce-last mce-abs-layout-item mce-formitem" hidefocus="1" tabindex="-1" style="left: 0px; top: 40px; width: 186px; height: 30px;"><div id="mceu_146-body" class="mce-container-body mce-abs-layout" style="width: 186px; height: 30px;"><div id="mceu_146-absend" class="mce-abs-end"></div><label id="mceu_136-l" class="mce-widget mce-label mce-first mce-abs-layout-item" for="mceu_136" aria-disabled="false" style="line-height: 16px; left: 0px; top: 7px; width: 136px; height: 16px;">border</label><input id="mceu_136" class="mce-textbox mce-last mce-abs-layout-item" value="" hidefocus="1" aria-labelledby="mceu_136-l" style="left: 136px; top: 0px; width: 40px; height: 28px;"></div></div></div></div></div></div></div></div></div> 

you have wrong selector because:

1) window.parent returns window element object , tried using jquery selector incorrect syntax along it.

2) there no child selector in jquery.

you can rather use:

$(window.parent).find(".mce-container-body input:first").attr("id"); 

if want id of inputs in array:

 $(window.parent).find(".mce-container-body input").map(function(){      return this.id;  }).get(); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -