Reputation: 10400
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);
Upvotes: 3
Views: 28993
Reputation: 21727
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.
Upvotes: 4
Reputation: 37506
Why not just do this?
var message = logReg.query('#responseMessage').html();
var isValid = logReg.query('#responseErrorMessage').html();
The top line of your code is problematic. It'll return an entire array of div tags. So when you do div.children('...') you're doing that for the entire list of divs.
Since you have the anchors for the specific elements, just look them up directly.
Upvotes: 0
Reputation: 187050
If you want to get the html of an element having an id, then you can simply use the id selector.
$("#responseMessage").html();
Upvotes: 4