2

I have a function that scans across HTML DOM tree and does the job. The problem is that function is written with JQUERY and I have to translate it to native HTML.

Looking for native javascript alternative for jQuery's .contents() method to translate the following line:

$myroot.contents().each(function (ind) {.....

Assuming that $myroot will be standard HTML element, how can I get all its contents?

Thanks in advance.

3
  • 1
    Node.childNodes Commented Sep 12, 2016 at 10:50
  • 1
    Do you mean vanilla javascript rather than 'native HTML'? Commented Sep 12, 2016 at 10:50
  • Sure :) I meant native javascript rather than native HTML :)) Commented Sep 13, 2016 at 18:01

1 Answer 1

1

If $myroot is something like this

$myroot = document.getElementsByClassName("classname");

then you can get contents like this

Array.prototype.forEach.call(elem, function(elem) {
    // Do stuff here
   console.log(elem.tagName);
});

Hope this helps. Thanks !!

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

1 Comment

Thanks. Exactly what I was looking for.

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.