Click here to Skip to main content
16,005,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay so I want a button i have to be disabled when there are no images displaying. it works the first time but any other time there are no images it does not disable the button. I have another button that has the roll function attached to it so when it is executed it generates images . after each round the images disappear so the other button i have should be disabled .

JavaScript
function roll(die,i){

       rando = Math.floor(Math.random()*6)+1;

        die.html("<img  src=images/die"+rando+".png>");
         die.find('img').attr('class', rando);

         dice_value[i]=rando;

      $('img').height(50);


   };

if($('img').length==0){
  $('.button2').prop('disabled',true);
}


What I have tried:

ive tried using this if statement
Posted
Updated 3-Mar-17 17:27pm
Comments
Karthik_Mahalingam 3-Mar-17 23:17pm    
run this in console window
$('img').length

Use a debugger, put a breakpoint and when execution stops, inspect the $('img') object and see if your condition is met.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
Comments
Member 12995420 3-Mar-17 20:42pm    
yeah i am which is why i am confused. my condition is being met and i have no errors
Member 12995420 3-Mar-17 20:50pm    
however i just realized the problem , something else was undoing it.
This code
if($('img').length==0){
  $('.button2').prop('disabled',true);
}
has to be placed in some function which will be executed upon this event:
Quote:
after each round the images disappear so the other button i have should be disabled .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900