Jquery.contains() Does Not Work Properly
I should get an 'alert' in the following case, but I am not getting any 'alert'. I am trying a simple example of jQuery.Contains().
$(document).ready(function(){
var alpha = $.contains(document.body,$("p")[0])
if (alpha) {
alert(alpha);
}
});
Arguments are always DOM elements, not simple text.
For more details, see this.
Solution 3:
jQuery.contains only returns boolean and doe not have a callback. Try this code.
$(document).ready(function(){
alert($.contains(document.body,$('p')[0]));
});
Solution 4:
Usethis code you have error on this line (var alpha = $.contains('body','p'){)
<html>
<head><scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script>
$(document).ready(function(){
var alpha = $.contains('body','p');
alert(alpha);
});
</script></head><body><p>This is a paragraph.</p></body>
</html>
Post a Comment for "Jquery.contains() Does Not Work Properly"