0

When I do

var el = document.querySelector('.some-class');

I get the plain HTML.

How then do I get access to the Javascript node element?

I can see it when I do dir(el) in the console.

2 Answers 2

1

This is the dom itself. You can manipulate the element with only this. Why it is showing the HTML, it is just a common way that the console shows you. If you want to add a class for example, you can do.

var el = document.querySelector('.some-class');
el.classList.add('test')

This will work as it should. If you want to HTML of the element, you could also do:

el.outerHTML

Hope this helps you.

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

Comments

1

Actually, document.querySelector() returns an element object, which implements the Element interface which inherits from the Node interface.

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.