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>
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>
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>
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);
}
});
});