Is there any method to have the same coding for the click function of two different id elements in one click function?
For example,I have two link elements with ids, myFormsTabSubmitted and formStatusSubmitted. Both the link is of same functionality. When I click both these links, the same div element("submitted") is showed,and other divs are hidden.
So instead of writing two click functions, one for myFormsTabSubmitted and another for formStatusSubmitted, can I have one click function for both? Like
$('#myFormsTabSubmitted #formStatusSubmitted').click(function(){
$('#allMyForms').hide();
$('#draftedMyForms').hide();
$('#submittedMyForms').show();
$('#myFormsTab').find(".selected").removeClass();
$('#myFormsTabSubmitted').addClass("selected");
});
The id must be unique. There can be only one element in the document with the given id . If there are multiple elements with the same id , then the behavior of methods that use it is unpredictable, e.g. document. getElementById may return any of such elements at random.
HTML id Attribute. The HTML id attribute is used to specify a unique id for an HTML element. You cannot have more than one element with the same id in an HTML document.
Just use the comma separator in the selector:
$("#myFormsTabSubmitted, #formStatusSubmitted").click(function() {
// do stuff
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With