Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

convert h2 to h1 jQuery

/***
   Changes an HTML elements HTML tag from one type to another
   @ Params:
   elemSelector - the css selector of the element you want to change
   tagType - the type of tag to change the element to
 ***/
function changeHTMLTag(elemSelector,tagType)
{
    jQuery(elemSelector).replaceWith(
	function()
	{
	    return jQuery("<"+ tagType +">", {class: this.className, html: jQuery(this).html()});
	}
    );
}
// example usage:
changeHTMLTag('#myElement','h2'); // This will change the element into a h2 tag
Source by forum.jquery.com #
 
PREVIOUS NEXT
Tagged: #convert #jQuery
ADD COMMENT
Topic
Name
8+2 =