Archive for October 2013

How to find the first parent element in jQuery?

To find the first parent element using jQuery.

HTML:

  1. <div class="container1">
  2.    <div class="container2">
  3.       <div class="container3">
  4.          <div class="container4">
  5.              <div class="element">
  6.              ...
  7.          </div>
  8.       </div>
  9.    </div>
  10. </div>

Solution:

  1. $(".element").parents();
will give all parents of .element(including html and body)
DEMO

To find any specific parent, suppose container1 then
  1. $('.element').parents('.container1')
DEMO

jQuery .parents() generally find all parents, but if you passed a selector then it will search for that.
Sunday 27 October 2013
Posted by Jebastin
Tag :

How to check 'undefined' value in jQuery?

One option is to use typeof operator:

  1.  if (typeof val === "undefined") { // ... }
It returns a string indicating the type of the variable or other unevaluated operand. The main advantage of this method is that it will never raise an exception in case if variable val does not exist.
Friday 25 October 2013
Posted by Jebastin
Tag :

Link To This Post/Page

Spread The Word

Add this button to your blog:
JJ Technology Solutions

Blog Archive

Trackers

eXTReMe Tracker
facebook

- Copyright © JJ Technology Solutions - Powered by Source Code Solutions -