javascript - Boolean of one element with jQuery -
i have code
<main class="ok">my text</main> <script> $(document).ready(function() { if ( $('body').not('main.ok') ) { // or if ( boolean ( $('main.ok') ) == false ) { // main element not available alert (' main element "ok class" not available '); } else { alert (' main element "ok class" available '); } }); </script>
but code doesn't work !
and alert
main element "ok class" not available
so u guys suggest me ?
use hasclass()
determine whether of matched elements assigned given class.
$('body main').length && $('body main').hasclass('ok')
code
if ($('body main').length && $('body main').hasclass('ok')) { alert(' main element "ok class" available '); } else { alert(' main element "ok class" not available '); }
Comments
Post a Comment