Browsing all articles tagged with jquery - Share Programming Tips
Sep
18

Set dynamic attributes to entire site

Today while integrating theme in WordPress i have asked to my TL that is it possible to set title attribute for a tag of the HTML without actually placing it to entire site.

She has given me solution which i am sharing here,

jQuery(function () {
 
//set dynamic title attribute to <a> tag
 
jQuery('a').each(function() {
 
//check broken links for the SEO
if(jQuery(this).attr("href")=="#" || jQuery(this).attr("href")=="")
jQuery(this).attr("href","javascript:void(0);");
if(jQuery(this).text()!='')
jQuery(this).attr("title",jQuery(this).text());
});
 
//set dynamic title attribute for the <input type=' submit'> tag
jQuery('input:submit').each(function() {
if(jQuery(this).val()!='')
jQuery(this).attr("title",jQuery(this).val());
});
 
//set dynamic title attribute for the <input type=' button'> tag
jQuery('input:button').each(function() {
if(jQuery(this).val()!='')
jQuery(this).attr("title",jQuery(this).val());
});
 
});

Above code will set title attribute for the <a> and <input> tags.

And this way developer can place such dynamic attributes which saves lots of development and designing time.

Follow us on Twitter! Follow us on Twitter!

Search in this website

our sponsors

latest comments

Find us on Facebook

Top Authors

35 posts
saurabh
22 posts
10 posts

Find us on stackoverflow

Polls

Tell us who you are

View Results

Loading ... Loading ...

My Bookmarks

Sponsers Link