- February 8, 2017
- Posted by: Bharat Patel
- Category: Uncategorized
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
[code:js]
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=’https://www.isummation.com’;
}
}));[/code]