Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • DOM Element Replacement in jquery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 247
    Comment on it

    If you want to replace html element with some other element, the jquery replaceWith method can be used.

    You can replace some specified DOM element with the other html or DOM element. The replaceWith() method is used in this case.


    selector.replaceWith( content )

    The content inside replaceWith method can be a html element or it can be a text.


          <title>The jQuery Example</title>
          <script type = "text/javascript" src = ""></script>
          <script type = "text/javascript" language = "javascript">
             $(document).ready(function() {
                $("#divone").click(function () {
                   $(this).replaceWith("<h1>some other data</h1>");
             #divone{ margin:18px;padding:15px; border:2px solid #ccc; width:50px;}
          <p>Click on the below:</p>
          <span id = "answer"> </span>
          <div id = "divone" style = "background-color:red;">
             some data

 0 Comment(s)

Sign In

Sign up using

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: