I am trying to get the div w" /> I am trying to get the div w" /> I am trying to get the div w"/>

Using multiple selectors using document query

45 views Asked by At

I have a HTML tag

<div class="selected focused leafNode" data-test-id="4048800800000000::1" id="treeNode_5B9843E1"></div>

I am trying to get the div with a given data-test-id that has a '.selected' class.

I used the following query, but it doesn't seem to work

dojo.query('div.selected[data-test-id="404880f800000000::1"]')

Can anyone tell me how to call this right?

1

There are 1 answers

3
Sudhir kumar On

You can simply use hasClass method for checking the class and then get data-testing-id attribute data-test-id

$(function() {
      if($("div").hasClass("selected")) {
       let val =  $("div").attr("data-test-id");
         console.log(val) // 4048800800000000::1   
      }
      
    });