Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

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!');
}

Wednesday, January 25, 2012

[jQuery] Change Element Class Name

Example:
<div>
  <span class=”old_class”>hello there!</span>
</div>

Change the class using jQuery:
$('div span').removeClass('old_class').addClass('new_class');

Result:
<div>
  <span class="new_class">hello there!</span>
</div>
Related Posts Plugin for WordPress, Blogger...