12 jQuery Questions and Answers You Should Be Reading on StackOverflow

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!

  1. How would I know if an element is hidden?

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.

  1. How do I get selected text in select box?

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

  1. 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

  1. How would I know if a checkbox is checked or unchecked?

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

  1. How to select a child element?

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

  1. event.preventDefault() vs. return false

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

  1. Example of using jQuery .closest() method.

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!

  1. 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) {}

  1. How would I know which radio button is selected?

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

  1. How to select multiple classes?

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

  1. How to select an element by its name, not by class or id?

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.

  1. What if Google hosted jQuery is blocked?

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!

Hi! I'm Mike Dalisay, the co-founder of codeofaninja.com, a site that helps you build web applications with PHP and JavaScript. Need support? Comment below or contact [email protected]

I'm also passionate about technology and enjoy sharing my experience and learnings online. Connect with me on LinkedIn, Twitter, Facebook, and Instagram.