New method Passing Attributes to jQuery 14

Posted by Bharat Patel on June 02, 2010
  0 comments

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';
        }
}));

 

Comments


Leave a comment

Tell us about yourself
Your Name     (required field)
Your Email Address     (required field)
Website URL      
Comment and preferences
Your Comment  
   
  Subscribe to this comment thread