开发者

jQuery get div content

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('#res开发者_JAVA技巧ponseMessage').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);


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.


If you want to get the html of an element having an id, then you can simply use the id selector.

$("#responseMessage").html(); 


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜