jonnyhitek
jonnyhitek

Reputation: 1551

Trying to get id of a div using its class

I have a strange problem, I am trying to implement drag and drop using dojo, this all works fine. However I need to attain the id of all divs with a certain class, I have been unable to do so using the dojo.query method e.g. :

        var totalNumDays = dojo.query(".shiftDropper");
        console.log(totalNumDays.id);

This results is undefined ?

I have also tried using the following:

var totalNumDays = dojo.query(".shiftDropper");
var idName = totalNumDays.attr("id");
console.log(idName);

However this returns the results in a strange way it returns the id's but as an object ? If anyone could point me the right direction it would be great, I will include the HTML source to give u guys a clearer idea of the problem:

        <div id="day1dropper" class="shiftDropper">
            <table class="tableDropTarget" id="day1" dojoType="dojo.dnd.Target" accept="shift" copyOnly="false">
                <tbody></tbody>
            </table>
        <div id="clearButton">Clear Shifts</div>
    </div>

    <div id="day2dropper" class="shiftDropper">
            <table class="tableDropTarget" id="day1" dojoType="dojo.dnd.Target" accept="shift" copyOnly="false">
                <tbody></tbody>
            </table>
        <div id="clearButton">Clear Shifts</div>
    </div>

Thanks in advance

Upvotes: 0

Views: 618

Answers (1)

virsir
virsir

Reputation: 15489

 var totalNumDays = dojo.query(".shiftDropper")[0];
 console.log(totalNumDays.id);

dojo.query returns an array.

Upvotes: 2

Related Questions