Change the opecity decrease and increase on each click of button

Home Forums Web Development HTML, JavaScript and CSS Change the opecity decrease and increase on each click of button

Tagged: 

This topic contains 0 replies, has 1 voice, and was last updated by  Shalabh 4 years, 6 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #4924

    Shalabh
    Participant

    I have a div element as:

    <div id="divImage" class="opdiv" />
    <input id="ChangeOp" value="Set fade" />

    My problem is that the opacity of the divImage should be reset (increase or decrease .1 ) on the click of button. for example first time when user click on the button the opacity should be .9 and on the second click it should be .8 and so on..When it goes to 0 then it should be increase by .1.

    I have tried the javascript code for doing this but fails

    var opacity;
    opacity= 1;
     $('#ChangeOp').each(function() {
            $('#divImage").css('opacity', opacity);
      opacity = opacity - .1;
      });

    But when the opacity becomes 0 then what how to increase. Please help to complete the above code.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.