In jquery we put select child element using like this
$('.parentClass .childClass')....
is there any way to select child class using parent class in javascript
For Javascript try this
document.querySelectorAll('.parentClass .childClass')
You can use css selector as argument in this function. This function not supported in lower version of IE
html:
<ul class="example">
<li class="child">Coffee</li>
<li class="child">Tea</li>
</ul>
javascript:
var list = document.getElementsByClassName("example")[0];
list.getElementsByClassName("child")[0].innerHTML = "Milk";
The question is not clear but if you want to get all nested child elements which has class, this can be work:
$("parentElementSelector").find("[class]")
But if you want to just next child elements you can use this:
$("parentElementSelector").children("[class]")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.