What is wrong with this simple jQuery code?

This is simple jQuery code, what I want to do is hide #bling, but it doesn’t

<script language="javascript">

 $("document").ready(function() {  

      $('#bling').hide();  


  }); 

</script>

<div id="bling" style="background-color:#FFFF66; width:100px; height:100px;"></div> 

Thanks Dave

+3
source share
6 answers

Change $("document")to$(document)

+9
source

I tested the code and it works fine, although you have a line "document"instead documentand an ancient attribute languagein the script tag ...

Use type="text/javascript"a script tag. You can simply send the function to the jQuery object as a shortcut to use the ready-made function:

<script type="text/javascript">

$(function(){
   $('#bling').hide();
});

</script>

However, since this is not the code that is the problem, there is something else on your page.

  • Make sure you have included jQuery script successfully.

  • , id "bling". .

  • Javascript. IE . Firefox Javascript.

+3

It works for me as it is. Try using jquery from the jquery site, code below.

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script language="javascript">

 $("document").ready(function() {  

      $('#bling').hide();  


  }); 

</script>

<div id="bling" style="background-color:#FFFF66; width:100px; height:100px;">aaaaaaaa</div>

See if this works.

+1
source

Edit:

$ ("document"). ready (function () {

//.. before..

$ (function () {

0
source

Make sure you include the javascript jQuery file in your HTML code. In addition, your code should look something like this:

<script type="text/javascript">
$(document).ready(function() {  
   $('#bling').hide();  
}); 
</script>

Note the attribute typein the script tag, as well as documentnot in quotation marks.

0
source

Make sure jQuery loads:

<script language="javascript">

 $(document).ready(function() {  

      alert('Can you hear me now?');
      //$('#bling').hide();  


  }); 

</script>
0
source

Source: https://habr.com/ru/post/1729865/


All Articles