JQuery Mini-tips

Get a DOM object from a JQuery obj

$('#' + id).get(0); //get the dom object from the jquery wrapper

Only include object if JQuery is available

//only include if jquery is available
if (typeof jQuery != 'undefined') {
   //class goes here
}

Get selected item in select list

$('#selectList').val();//value
$('#selectList :selected').text(); //text of option

Check an element exists

if ($('#myDiv').length) {
    // your code
}

Select item in Select

if ($('#Select option').length > 0)
  $("#Select option[value='" + OptionValue + "']").attr('selected', 'selected');

JavaScript only for Internet Explorer

 if ($.browser.msie) {
   // Internet Explorer is a sadist.
 }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.