Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to change HTML tags using Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 194
    Comment on it

    Hi If you want to change the tags of HTML with another tags then you can perform this action using JS in realitme. Let's consider and example to change the <h2> tag with <i> using JS.

    <h2 class="xyzxterms" style="cursor: default; ">Converting Text to Italic</h2>
    

    And write the JS code :-

    var attrs = { };
    $.each($("h2")[0].attributes, function(idx, attr) {
        attrs[attr.nodeName] = attr.nodeValue;
    });
    $("h2").replaceWith(function () {
        attrs.text = $(this).text();
        return $("<i />", attrs);
    });
    

    Output:-

    Converting Text to Italic

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: