jQuery: Get selected element tag name

You can call .prop(“tagName”). Examples: jQuery(“<a>”).prop(“tagName”); //==> “A” jQuery(“<h1>”).prop(“tagName”); //==> “H1” jQuery(“<coolTagName999>”).prop(“tagName”); //==> “COOLTAGNAME999” If writing out .prop(“tagName”) is tedious, you can create a custom function like so: jQuery.fn.tagName = function() { return this.prop(“tagName”); }; Examples: jQuery(“<a>”).tagName(); //==> “A” jQuery(“<h1>”).tagName(); //==> “H1” jQuery(“<coolTagName999>”).tagName(); //==> “COOLTAGNAME999” Note that tag names are, by convention, returned CAPITALIZED. If … Read more

Preloading images with jQuery

Quick and easy: function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $(‘<img/>’)[0].src = this; // Alternatively you could use: // (new Image()).src = this; }); } // Usage: preload([ ‘img/imageName.jpg’, ‘img/anotherOne.jpg’, ‘img/blahblahblah.jpg’ ]); Or, if you want a jQuery plugin: $.fn.preload = function() { this.each(function(){ $(‘<img/>’)[0].src = this; }); } // Usage: $([‘img1.jpg’,’img2.jpg’,’img3.jpg’]).preload();

jQuery selectors on custom data attributes using HTML5

$(“ul[data-group=’Companies’] li[data-company=’Microsoft’]”) //Get all elements with data-company=”Microsoft” below “Companies” $(“ul[data-group=’Companies’] li:not([data-company=’Microsoft’])”) //get all elements with data-company!=”Microsoft” below “Companies” Look in to jQuery Selectors :contains is a selector here is info on the :contains selector

How to find if an array contains a specific string in JavaScript/jQuery?

You really don’t need jQuery for this. var myarr = [“I”, “like”, “turtles”]; var arraycontainsturtles = (myarr.indexOf(“turtles”) > -1); Hint: indexOf returns a number, representing the position where the specified searchvalue occurs for the first time, or -1 if it never occurs or function arrayContains(needle, arrhaystack) { return (arrhaystack.indexOf(needle) > -1); } It’s worth noting … Read more

Get class list for element with jQuery

You can use document.getElementById(‘divId’).className.split(/\s+/); to get you an array of class names. Then you can iterate and find the one you want. var classList = document.getElementById(‘divId’).className.split(/\s+/); for (var i = 0; i < classList.length; i++) { if (classList[i] === ‘someClass’) { //do something } } jQuery does not really help you here… var classList = … Read more

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