javascript - Comparing the InnerHTML of an object in jQuery -


i able .html() of sharepoint textbox, in dom appears <div>. when textbox empty, innerhtml of <div> appears <p></p>.

because particular textbox not appear (i control appearance based on selected value of previous checkbox on form), can't make required, i'm doing dynamically checking if filled in or not on-save. means seeing if innerhtml <p></p> or <p>asdf<span id="ms-rterangecursor-start" rtenodeid="1"></span><span id="ms-rterangecursor-end"></span></p>, asdf text entered (sharepoint puts in gobbly-gook in-between).

what thought check this, explainfield representing <div> jquery variable, similar done @ http://makandracards.com/makandra/13445-compare-two-jquery-objects-for-equality :

var $divnode = $('div'); var $pnode = $('p'); var $testnode = $divnode.html($pnode); if (explainfield.is($(testnode))) {      // got <p></p>     return false;  // go no further } else {     return true;  // we're ok } 

but comparison not work. when there no text, statement should met , return false. instead, returns true , thinks have text when don't. how can make comparison work , return false if finds <p></p>?

so, try following bit easier trying.

var $divnode = $('div'); var html = $divnode.html();  if ( $(html).children().length > 0 ) {     alert ("not empty"); } else {     alert ("empty"); } 

demo


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -