Posts

Showing posts with the label Jquery Ui

Animating AddClass/removeClass With JQuery

Answer : Since you are not worried about IE, why not just use css transitions to provide the animation and jQuery to change the classes. Live example: http://jsfiddle.net/tw16/JfK6N/ #someDiv{ -webkit-transition: all 0.5s ease; -moz-transition: all 0.5s ease; -o-transition: all 0.5s ease; transition: all 0.5s ease; } Another solution (but it requires jQueryUI as pointed out by Richard Neil Ilagan in comments) :- addClass, removeClass and toggleClass also accepts a second argument; the time duration to go from one state to the other. $(this).addClass('abc',1000); See jsfiddle:- http://jsfiddle.net/6hvZT/1/ You could use jquery ui's switchClass , Heres an example: $( "selector" ).switchClass( "oldClass", "newClass", 1000, "easeInOutQuad" ); Or see this jsfiddle.

Check / Uncheck Checkbox Using Jquery?

Answer : For jQuery 1.6+ : .attr() is deprecated for properties; use the new .prop() function instead as: $('#myCheckbox').prop('checked', true); // Checks it $('#myCheckbox').prop('checked', false); // Unchecks it For jQuery < 1.6: To check/uncheck a checkbox, use the attribute checked and alter that. With jQuery you can do: $('#myCheckbox').attr('checked', true); // Checks it $('#myCheckbox').attr('checked', false); // Unchecks it Cause you know, in HTML, it would look something like: <input type="checkbox" id="myCheckbox" checked="checked" /> <!-- Checked --> <input type="checkbox" id="myCheckbox" /> <!-- Unchecked --> However, you cannot trust the .attr() method to get the value of the checkbox (if you need to). You will have to rely in the .prop() method. You can use prop() for this, as Before jQuery 1.6 , the .attr() me...