Friday, June 15, 2012

[jQuery] Know If An Element Exist

Basic syntax:
$('element').length == 0

Example:
if($('div#mydiv').length == 0)
{
    $('body').append('
        <div id="mydiv">hello world!</div>
    ');
}
else
{
    $('div#mydiv').html('hello universe!');
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...