0

In the below code how to remove the hyperlink after getting the innerHTML:

function test(obj)
{
  var a=obj.innerHTML
  //remove obj element here
}

$p = $('<a id="name" onclick="var ele=test(this);">').html( "test" );
$('#questions').append( $p );

2 Answers 2

2

You can remove an element using the DOM method removeChild. If you start with a reference to the child [as you seem to in your test function (the obj argument)], you can remove it like this:

obj.parentNode.removeChild(obj);

(Your question is also tagged jQuery but I see someone pointed you to jQuery's remove function and you said you didn't want to use that. In any case, for completeness I've noted it here.)

Sign up to request clarification or add additional context in comments.

Comments

0

You're using jQuery, so just do:

$(obj).remove()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.