Whether a variable is undefined [duplicate]

jQuery.val() and .text() will never return ‘undefined’ for an empty selection. It always returns an empty string (i.e. “”). .html() will return null if the element doesn’t exist though.You need to do: if(page_name != ”) For other variables that don’t come from something like jQuery.val() you would do this though: if(typeof page_name != ‘undefined’) You … Read more

What is content-type and datatype in an AJAX request?

contentType is the type of data you’re sending, so application/json; charset=utf-8 is a common one, as is application/x-www-form-urlencoded; charset=UTF-8, which is the default. dataType is what you’re expecting back from the server: json, html, text, etc. jQuery will use this to figure out how to populate the success function’s parameter. If you’re posting something like: … Read more

How to scroll up or down the page to an anchor using jQuery?

Description You can do this using jQuery.offset() and jQuery.animate(). Check out the jsFiddle Demonstration. Sample function scrollToAnchor(aid){ var aTag = $(“a[name=””+ aid +””]”); $(‘html,body’).animate({scrollTop: aTag.offset().top},’slow’); } scrollToAnchor(‘id3’); More Information jsFiddle Demonstration jQuery.offset() jQuery.animate()

jQuery table sort

I came across this, and thought I’d throw in my 2 cents. Click on the column headers to sort ascending, and again to sort descending. Works in Chrome, Firefox, Opera AND IE(8) Only uses JQuery Does alpha and numeric sorting – ascending and descending $(‘th’).click(function(){ var table = $(this).parents(‘table’).eq(0) var rows = table.find(‘tr:gt(0)’).toArray().sort(comparer($(this).index())) this.asc = … Read more

Get index of selected option with jQuery

The first methods seem to work in the browsers that I tested, but the option tags doesn’t really correspond to actual elements in all browsers, so the result may vary. Just use the selectedIndex property of the DOM element: alert($(“#dropDownMenuKategorie”)[0].selectedIndex); Update: Since version 1.6 jQuery has the prop method that can be used to read … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)