Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:48:16+00:00 2026-06-01T12:48:16+00:00

My code: var parent = document.createElement(‘div’); var pen = document.createElement(‘div’); var dog = document.createElement(‘div’);

  • 0

My code:

var parent = document.createElement('div');
var pen = document.createElement('div');
var dog = document.createElement('div');
dog.className = "dog";
pen.appendChild(dog);
parent.appendChild(pen);
dojo.query("> *", parent).forEach( function(node){
    if(node.className == "dog")alert('bark');
});
dojo.query("> .dog", parent).forEach( function(node){
    alert('bark');
});

I’m getting no alert “bark”s. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:48:18+00:00Added an answer on June 1, 2026 at 12:48 pm

    You’re problem is that the generated html doesn’t match the selector:

    <div title="parent">
        <div title="pen">
            <div class="dog">
            </div>
        </div>
    </div>
    

    Because > * will only match pen and > .dog won’t match. You could change these to:

    var parent = document.createElement('div');
    var pen = document.createElement('div');
    var dog = document.createElement('div');
    dog.className = "dog";
    pen.appendChild(dog);
    parent.appendChild(pen);
    dojo.query("> * > *", parent).forEach(function (node) {
        if (node.className == "dog") {
            alert('bark');
        }
    });
    dojo.query("> * > .dog", parent).forEach(function (node) {
        alert('bark');
    });
    

    Here’s a fiddle: http://jsfiddle.net/pTqmL/

    Edit

    Or if it just needs to be inside of parent:

    dojo.query("*", parent).forEach(function (node) {
        if (node.className == "dog") {
            alert('bark');
        }
    });
    dojo.query(".dog", parent).forEach(function (node) {
        alert('bark');
    });
    

    Based on your comment, I think the core thing you might be overlooking/unaware of is that query is scoped inside of parent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have that code var p = document.createElement('p'); var a = document.createElement('a'); $(a).attr('href', 'http://www.my-site.com');
If I have a var t = document.createTextNode(text) parent.appendChild(t); Is it possible to simply
I get a parse error from Safari with this code: for (var i=0; i<parent.frames.length;
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
Here's my javascript code: <script type=text/javascript> $(document).ready(function() { var currentInput = ''; var currentLabel
I have this code: $(document).ready(function() { $(.vote, .vote1).click(function() { var id = $(this).attr(id); var
Code: var result = db.rows.Take(30).ToList().Select(a => AMethod(a)); db.rows.Take(30) is Linq-To-SQL I am using ToList()
The code: var foo = /\</; When I go to jslint.com and enter that
This code var offset = $('#snapwrap_inner').offset(); alert(offset.left) in FF returns 0px but in Opera
I have the following code: var sl: THashedStringList; begin sl:= THashedStringList.Create; sl.Duplicates := dupIgnore;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.