Getting information from nested div and class in HTML with javascriptAsk Question

问题:

I'm trying to get to the div class="article" nested inside a div called div id="tabs=main from this a HTML-page that looks like this:

pastebin

I have tried something like this but with no result:

var targetAbs = doc.querySelectorAll("article");

Anyone have any tips for me? Not even sure I'm suppose to use this queryselector. I have also tried the getElementsByClassName, but I think since it's nested I can reach it.

回答1:


doc isn't a standard variable provided by the browser. You are looking for document.

Class selectors begin with a .. "article" is a type selector and will match <article> elements.

回答2:


As your element has a class of article, you need to use the following code:

doc.querySelectorAll(".article");

You need to place a . in front of the selector when it is referring to a class.

标签: html
© 2014 TuiCode, Inc.