Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an element inside nested divs by class name?

Tags:

javascript

A webpage with HTML looks like this:

<div id="Parent-div" > </div>
<div class="first-child-div"> </div>
<div class=" second-child-div"> 
    <div class="first-grand-child"> </div>
    <div class="second-grand-child"> </div>
    <div class="Third-grand-child"> 
        <div class="Grand-grand child"> 
           <button  class="Confirm-button">Confirm!</button> 
        </div>
    </div>
</div>

I've Tried This code using greasemonkey to remove a button from the div with the class named "Grand-grand child"

This is what I did:

var targetDiv = document.querySelector("#<Parent-div>. Grand-grand.child");

targetDiv.innerHTML = "Hello world!";

The Button wasn't replaced by the Hello world! text, What did I do wrong?

like image 369
Haz Avatar asked Feb 20 '13 15:02

Haz


1 Answers

document.querySelector('.Grand.grand.child');

Demo: http://jsfiddle.net/yGv3v/

like image 73
PeeHaa Avatar answered Oct 16 '22 04:10

PeeHaa