Is there a way to call methods by their name in jQuery? For example:
var condition = true;
$('div').execute(condition ? 'show':'hide');
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, use the
[]notation to access properties of the jQuery object (rather than literal ones using.):You can also do:
http://api.jquery.com/toggle/
http://www.jibbering.com/faq/faq_notes/square_brackets.html
Edit: Just in case you prefer your own style of coding, you could add this:
Then you can do like:
or