Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Deleting Elements using Javascript

    • 0
    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 99
    Comment on it

    In Javascript , you can't delete the element directy if you want to delete the element , then first you have to find its parent element and delete it using remove() method .Because DOM ( Document Object Model ) doesn't support removing an element directly .
    Example ->

    <div id=" parent " >
    <p id = "child" >I am user </p>
    </div><br>
    

    Code deleted with id ->
    var child = document.getElementById(child);//get element
    var div = document.getElementById(parent);//get parent element
    parent.removeChild(child);
    Now if you want to get parent element automatically , then you can use parentNode property of the child to find the parent property automatically .

    var child = document.getElementById(child);//get element<br> 
    child.parentNode.removeChild(child);<br>//By using this you can automatically find the parent element
    

 1 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: