0

How to get the all class name with in tag, I want get class name one and two, Any one please help me

<div id="svgcanvas" style="position:relative">
    <div class="one"></div>
    <div class="two"></div>
 </div> 
Shanmuga kumar
  • 165
  • 1
  • 4
  • 12

3 Answers3

0

You can get that using JQUERY .html() method.

$('#svgcanvas').html();
Nihar Sarkar
  • 1,187
  • 1
  • 13
  • 26
0

You can use id of element along with attribute selector for div to target all the div elements inside #svgcanvas

$('#svgcanvas div')

iterate over the set of returned elements. inside each iteration, iterate over the attributes of that element as shown in this solution here:

$('#svgcanvas div').each(function(){
  $.each(this.attributes, function() {
   // this.attributes is not a plain object, but an array
   // of attribute nodes, which contain both the name and value
   if(this.specified) {
     console.log(this.name, this.value);
   }
  });
});

$('#svgcanvas div').each(function(){
  $.each(this.attributes, function() {
   // this.attributes is not a plain object, but an array
   // of attribute nodes, which contain both the name and value
   if(this.specified) {
     console.log(this.name +"-"+ this.value);
   }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="svgcanvas" style="position:relative">
  <div id="one"></div>
   <div id="two"></div>
</div>
Community
  • 1
  • 1
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

You can do like this.

        $('#svgcanvas').each(function() {
          $.each(this.attributes, function() {
            // this.attributes is not a plain object, but an array
            // of attribute nodes, which contain both the name and value
              console.log(this.name, this.value);
            }
          });
        });
Dipak Thoke
  • 1,963
  • 11
  • 18