Reputation: 293
How to check body element (<body></body>) in prototype?
This is not working:
if( $('body').hasClassName("catalog-product-view") ){
alert("yes");
}
if(!$('body').hasClassName("catalog-product-view") ){
alert("no");
}
Thanks for any advice.
Upvotes: 0
Views: 2729
Reputation: 29
to catch the body element do :
$(document.body)
this will return the body element !
to check the class use :
$(document.body).hasClassName("catalog-product-view")
and finally you can do what you need with :
$(document.body).hasClassName("catalog-product-view") ? alert("yes") : alert("no");
Upvotes: 2
Reputation: 10092
That code is looking for an element with an id
of 'body'
. Try giving the <body>
an id and referencing that.
Edit: or, looking at How to add an element to 'body' using Prototype?, use $$('body')[0]
Upvotes: 1