Posted by Bharat Patel on June 02, 2010 |
|
Hello Friends,
jQuery supports adding attributes to collection of elements with Attr function. Previously if we wanted to add stylesheet then we had to apply CSS function similar to event handling. But jQuery 1.4 introduced new method for adding attributes, stylesheet, event handling , etc. There is no need to add attr, css, bind or etc function for handling the element. We can write directly with element. We can use old method also. Please refer below example for better understanding. I hope you may like this one. This one is shorthand method for adding attributes. You need to add jQuery 1.4 js in your page.
jQuery 1.4 New method for passing attributes
jQuery('body').append(
jQuery('<a />',{
id : 'first',
href : '#',
rel : 'external',
text : 'click here',
css:{
'text-decoration' : 'none',
'font-weight':'bold',
'font-size':'14px',
'color':'red'
},
click : function(){
window.location='http://www.isummation.com';
}
}));
Posted by Bharat Patel on May 28, 2010 |
|
Hello Friends,
To delegate the "focus" and "blur" events you must use these new events, called "focusin" and "focusout". You can also use old events for handling focusing events in jQuery 14.
Syntax
jQuery(element).focusin(handler); jQuery(element).focusout(handler);
Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" language="javascript" src="jquery-1.4.2.min.js"></script>
<script>
jQuery(function(){
jQuery('#focus').focusin(function(){
jQuery(this).addClass('focused').val('Focus In');
});
jQuery('#focus').focusout(function(){
jQuery(this).removeClass('focused').val('Focus Out');
});
});
</script>
<style>
.focused{
background-color : #00f0ff;
}
</style>
</head>
<body>
<input type="text" name="focus" id="focus" />
</body>
</html>
Recent Comments