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

Wednesday, December 15, 2010

jQuery hasClassName prototypejs function: How to check if element has class with JQuery

To determine if an element has a class register with jQuery you can use the function .hasClass() which is shorter for .hasClassName() in prototypejs



if($('#target').hasClass('foo')){
// Do something
}

// With Prototype js you would use...

if($('target').hasClassName('foo')){
// Do something
}

Tuesday, December 14, 2010

jQuery add class to element: How to add a class to a div

Adding class or removing a css class from an element with jQuery or Prototypejs is very simple.



// With JQuery

$('#target').addClass('bar');

// With Prototypejs...

$('target').addClassName('bar');

// Removing a class with Jquery

$('#target').removeClass('bar');

// With Prototypejs...
$('target').removeClassName('bar');



Once again, jQuery has shorter function names which is awesome!