Manish Tiwari
Manish Tiwari

Reputation: 1866

show or hide button using jquery?

I have two button start and stop. on page load stop button hide and start button show. when i click start button this button hide and stop button show.

i am using .hide() method.

Jquery Code:

$(window).load(function ()
{
$('#stop').hide();
});

It's working but issue is when page load this (stop button) will show for a second(like a blink) and then hide. i want to hide completely mean i don't want to show stop button when page load.

Upvotes: 0

Views: 1170

Answers (4)

Afsaneh Daneshi
Afsaneh Daneshi

Reputation: 330

$(document).ready(function () {
    $("#btnStop").click(function (e) {
        e.preventDefault();
        $(this).hide();
        $("#btnPlay").show();
    })
    $("#btnPlay").click(function (e) {
        e.preventDefault();

        $(this).hide();
        $("#btnStop").show();
    })
})

Upvotes: 0

Wowsk
Wowsk

Reputation: 3675

Hide it once only the button has loaded, not the whole window.

$("#stop").load(function() {
  $(this).hide();
});

Otherwise you can always use CSS to hide it with display:none;

Upvotes: 2

Arun P Johny
Arun P Johny

Reputation: 388316

It is because you have used the load event handler, So till all the resources of the page is loaded the script is not executed.

One possible solution is to use a css rule, with the id selector to hide the element like

#stop{display: none;}

Upvotes: 0

Nutshell
Nutshell

Reputation: 8537

Maybe use CSS :

#stop { display: none; }

Upvotes: 1

Related Questions