javascript - get html from a variable by id -


i have variable name value in javascript code contain html data.i want data inside form specific id inside #mydiv

  var value="<div >              <p class="">hi cname@gmail.com</p>              <br/>             <br/>             <br/>             <div id="mydiv">               sgdhsagdhagh               dhsajdgasj               cjzjcg               </div>              </div>" 

thanks

you should create dom element, traverse , html() or .text()

  var value = '<div >\               <p class="">hi cname@gmail.com</p>\               <br/>\              <br/>\              <div id="mydiv">\                sgdhsagdhagh\                dhsajdgasj\                cjzjcg\                </div>\              </div>';      alert($(value).find('#mydiv').html())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

if need parent element, use

alert($('<div />', {html: value}).find('#mydiv').html()) 

Comments