Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get div content

Tags:

jquery

find

I have the following div structure, but this structure is changing

<div class="rt-container">
    <div class="rt-block">
        <div id="rt-mainbody">
            <div id="responseMessage">Welcome bogyoro. Now you are loged in.</div>
            <div id="responseErrorMessage">5</div>
        </div>
    </div>
</div>

I'm using the following code to get the responseMessage content:

var div = logReg.query("<div>").html(msg);
var message = div.children('#responseMessage').html();
var isValid = div.children('#responseErrorMessage').html();
if(isValid == null)
{
    message = div.find('#responseMessage').html();
    isValid = div.find('#responseErrorMessage').html();
}

But the isValid is null.

Update:

var logReg = {};
logReg.query = jQuery.noConflict(true);
like image 219
OHLÁLÁ Avatar asked Apr 12 '26 02:04

OHLÁLÁ


1 Answers

var isValid = div.children('#responseErrorMessage').html();

if (isValid == null) { }

Will always result in false. If the element exists, that is.

If an element is empty, the return will be an empty string. Try out if (isValid == "") { } instead.

like image 91
cllpse Avatar answered Apr 13 '26 16:04

cllpse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!