/** @id sipleSwitcher
* @classDescription Very simple style switcher using jQuery
*/
$(document).ready(function(){
$('#styleSwitch .button').bind('click', function(){
$('body').removeClass();//remove all the other classes
$('#styleSwitch .button').removeClass('selected');
$(this).addClass('selected');
switch(this.id){
case 'style1':
$('body').addClass('style1');
break;
case 'style2':
$('body').addClass('style2');
break;
case 'style3':
$('body').addClass('style3');
break;
}
return false;
});
});
Tag Archive for jquery
jQuery Simple Style Switcher
Error Messages for K2
Find & Replace this:
jQuery('#commenterror').show().html(request.responseText);
With:
jQuery('#commenterror').fadeIn().html(request.responseText).animate({opacity: 1.0}, 3000).fadeOut('slow');
Check for enter key using jQuery
$('#input_text').keyup(function(e) {
//alert(e.keyCode);
if(e.keyCode == 13) {
alert('Enter key was pressed.');
}
});
element’s absolute position in DOM Tree
myId = function(me){ return me.id ? '#' + me.id : '' }
myTag = function(me){ return me.tagName ? me.tagName.toLowerCase() : '' }
myClass = function(me){ return me.className ? '.' + me.className.split(' ').join('.') : '' }
breadcrumbs = function(me){
var path = [myTag(me) + myId(me) + myClass(me)];
$(me).parents().each(function() {
path[path.length] = myTag(this) + myId(this) + myClass(this);
});
return path.join(' < ');
}
$('body').click( function(){
alert( breadcrumbs(this) );
});
Checkbox status using jquery
var var_name = $('#checkbox_id').attr('checked')?1:0;
Radio button values using jquery
// for older jquery
var var_name = $("input[@name='radio_name']:checked").val();
// for jquery 1.3
var var_name = $("input[name='radio_name']:checked").val();
THE document ready
$(document).ready(function() {
// put all your jQuery goodness in here.
});
Replace DOM element and keep classes and id
jQuery.fn.replaceWith = function(replacement) {
return this.each(function(){
element = $(this);
$(this)
.after(replacement).next()
.attr('class', element.attr('class')).attr('id',element.attr('id'))
.html(element.html())
.prev().remove();
});
};
/*
usage example
$('a#fooid').replaceWith('<span></span>');
before:
<a id="fooid" class="whatever">some text</a>
after:
<span id="fooid" class="whatever">some text</span>
*/
Category: Uncategorized |
Tags: jquery