22

Can someone please tell me how I can hide this button after pressing it using jQuery?

<input type="button" name="Comanda" value="Comanda" id="Comanda" data-clicked="unclicked" />

Or this one:

<input type=submit  name="Vizualizeaza" value="Vizualizeaza">

4 Answers 4

39

Try this:

$('input[name=Comanda]')
.click(
     function ()
     {
         $(this).hide();
     }
);

For doing everything else you can use something like this one:

$('input[name=Comanda]')
.click(
     function ()
     {
         $(this).hide();

         $(".ClassNameOfShouldBeHiddenElements").hide();
     }
);

For hidding any other elements based on their IDs, use this one:

$('input[name=Comanda]')
.click(
     function ()
     {
         $(this).hide();

         $("#FirstElement").hide();
         $("#SecondElement").hide();
         $("#ThirdElement").hide();
     }
);
Sign up to request clarification or add additional context in comments.

6 Comments

thanx, but if I want to hide more buttons after clicking one button, what can I do?
Hiding more buttons by which parameter? I mean how you want to find them? by className, id, name, by what?
Every button has a unique id no classes nothing. I want to hide the 2 buttons in my example.
See the update. I think you should have a look at selector discussion in the jquery things. It will help you to do complex queries in finding elements. Cheers
Quick query - why not use the Id selector instead of the input name? Surely the Id will be quicker? As in Blender's answer ($('#Comanda')).
|
9

You can use the .hide() function bound to a click handler:

$('#Comanda').click(function() {
    $(this).hide();
});

1 Comment

@TothLudovicAndreas: Is this answer not working for you in some way? Can you elaborate on why not? When you start getting into "hide and show and other stuff" you start to leave the scope of a single question and move toward the scope of needing some tutorials on jQuery (or even JavaScript in general).
6

jQuery offers the .hide() method for this purpose. Simply select the element of your choice and call this method afterward. For example:

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

One can also determine how fast the transition runs by providing a duration parameter in miliseconds or string (possible values being 'fast', and 'slow'):

$('#comanda').hide('fast');

In case you want to do something just after the element hid, you must provide a callback as a parameter too:

$('#comanda').hide('fast', function() {
  alert('It is hidden now!');
});

Comments

1

It depends on the jQuery selector that you use. Since id should be unique within the DOM, the first one would be simple:

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

The second one might require something more, depending on the other elements and how to uniquely identify it. If the name of that particular input is unique, then this would work:

$('input[name="Vizualizeaza"]').hide();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.