Trying to select a specific node using Dojo

I am trying to select text from the name attribute of the anchor element of the last Commentdiv in a div Comments(i.e. comment_3037). How to choose it?

Here is my html:

<div id="Comments">
    <div class="Comment"><!-- last "Comment" element in the div -->
        <a name="comment_3037"></a>
        <a href=""><img src=""></a>
        <div>
            <div class="Stats">Some info goes here</div>
            <div class="Body">Comment goes here.</div>
        </div>
    </div>
</div>
+3
source share
1 answer

Corrected version (dojo.query always returns a modeler)

It will look something like this:

var nodelist = dojo.query('#Comments > .Comment:last-child > a[name]);'
var value = dojo.attr(nodelist.at(0), 'name');

Explanation: #Comments > .Commentselects all nodes with a class Commentinside node with id Comments. :lastChildreduces this choice to the last child. > a[name]selects all child children of type awith attribute name. The second line simply gets the value from the name node attribute.

, .

dojo, . ( dojo, ;))

Info

http://docs.dojocampus.org/dojo/query

, node, ( attr), "thisisthelinkiwant" ( ;)) 'Comments .thisisthelinkiwant:last-child'.

, css, .

+2

Source: https://habr.com/ru/post/1735524/


All Articles