I have HTML like that:
<div class="mydiv">
<script>
//my script
</script>
</div>
I want now check mydiv class has script or not. How can I do this with Jquery?
first go yo div with class .mydiv then find script then check its length
if( $(".mydiv").find("script").length)
{
alert("exist");
}
You can use Descendant Selector (“ancestor descendant”) with div. Using length with selector will show how many script (tag) element found in the container that is div with class mydiv
if($('.mydiv script').length)
{
//script tag found
}
Description: Selects all elements that are descendants of a given ancestor.
It would be:
$(function(){
if($('.mydiv').children('script').length>0){
// have script tab.
}
});