mto
mto

Reputation: 11

span and querySelector

I think my question is very easy but I am very new to javascript. I have a code that takes information from HTMl code with queryselector. The code of javascript is this:

  userData.innerHTML = resp.responseText;
              if(userData.querySelector('strong.username a')) {
                username = userData.querySelector('strong.username a').textContent;
              }

The code in the HTML page is this:

<span class="name-of-thumb">        
<a href="/houses/palo">North Carolina</a>
</span>

I need to use querySelector to get "North Carolina" from HTML. How should I modify the part "strong.username a" in the javascript code?

Thank you!

Upvotes: 1

Views: 12844

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191769

span.name-of-thumb a will work, or just .name-of-thumb a. That will select the first a node that is found with the .name-of-thumb parent.

Upvotes: 2

Related Questions