codeofaninja
website

12 jQuery Questions and Answers You Should Be Reading on StackOverflow

Photo of Mike Dalisay
Modified Friday, September 20, 2013
by - @ninjazhai
Hi guys! Below are twelve of the jQuery related questions and answers on StackOverflow that I found very useful during development. I opted to compile them here because I feel good reading those brilliant questions and answers by coders from around the world. Enjoy!


Sometimes you want some elements of your page to be visible, and if it is not visible, you want to tell the user about it. For example, a user must have a selection of data first before proceeding to new operation. If he has no selection (div is hidden), you can do a prompt that he must select something.



Ah, a drop-down list? Link # 2 above shows you how to get the user drop down list selection.


3. How to redirect a page?

Useful if you want to your users to see a page after an AJAX request, or you just want them to be redirected. I've written another example here, jQuery: Redirect onClick



For example, you want to enable a delete button if the user selected at least one data to delete, else, the delete button is disabled. I've written another example here: Check or Uncheck Checkboxes with jQuery And Get Selected with PHP



Teaches us how to select a child element and do it with faster performance (see the comment by Paul Irish).



I use return false; when I want to prevent a page refresh after clicking a submit button and doing an AJAX request.



I use jQuery .closest() method on selecting an element within a table with several rows. I probably have to write an example in another blog post, ha!


8. How would I know the existence of an element?

Useful if you want to perform something if an element exists in your page. The faster way is using if ($(selector).length) {}



This is how you will know if a user is a male or female, using jQuery!



Sometimes you want to to something to multiple classes at once. There's another example here.



If you're more familiar with an element's name or don't want to add a class or id name, you can use this cool technique.



In some countries, Google's domain name is banned. So if you are using a Google hosted jQuery library, you're site won't work. Link # 12 above shows you the fall back.


This can be the first part of the list, you can add more in the comments section below, or on our Facebook, Twitter or Google+!

And as always, thanks for reading!
For FREE programming tutorials, click the red button below and subscribe! :)
Thanks for the comments!
 
 
Fundamentals
"First do it, then do it right, then do it better."
~ Addy Osmani
"Talk is cheap. Show me the code."
~ Linus Torvalds
Let's Stay Connected!
g+ r
Android app on Google Play
© 2011-2014 The Code Of A Ninja. All rights reserved. Proudly Powered by Google Blogger. Images, logos, marks or names mentioned herein are the property of their respective owners.