Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your way of adding an id to an element is correct.</p> <p>The code runs fine for me in Firefox 17 and Chrome 23 but I have an issue in IE9. I suspect you may have the same issue.</p> <p>In IE9 the query <code>div[style=""]</code> returns no results. The funny thing is,it works fine in compatibility mode!</p> <p>t seems that in <strong>IE9</strong> in <strong>normal</strong> mode if an HTML element has an inline <strong>empty style</strong> attribute, that attribute is <strong>not</strong> being preserved when the element is added to the DOM.</p> <p>So a solution would be to use a different query to find the divs you want. You could try to find the divs with an empty style attributes <strong>OR</strong> with no style attribute at all.</p> <p>A query like this should work:</p> <pre><code>div[style=""], div:not([style]) </code></pre> <p>Take a look at the following example:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Test Page&lt;/title&gt; &lt;script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.8.2/dojo/dojo.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; dojo.require("dojo.NodeList-manipulate");//just for the innerHTML() function dojo.addOnLoad(function () { var nodeListByAttr = dojo.query('div[style=""], div:not([style])'); alert('Search by attribute nodeList length:' + nodeListByAttr.length); nodeListByAttr.attr("id", "main-body"); var nodeListByID = dojo.query('#main-body'); alert('Search by id nodeList length:' + nodeListByID.length); nodeListByID.innerHTML('Content set after finding the element by ID'); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div style=""&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload