How to get jQuery elements from an array of selectors



To use an array of strings as jQuery selectors I have found the need to append an empty string.
My bad example works because it coerces the ‘this’ object to a string.

Bad Example:

array = ["h1","p","div"];
$K(array).each(function() {
    console.warn( $K(this+"").children() );
});

Much Better Example:

array = ["h1","p","div"];
$K(array).each(function(index, value) {
    console.warn( $K(value).children() );
});

I had previously tried the following with out success

array = ["h1","p","div"];
$K(array).each(function() {
    console.warn( $K(this).children() );
});

The problem of what I was originally trying was that each item in the array wasn’t being treated as a string, I think.The problem of what I was originally trying was that ‘this’ is an object and not a string like I need for the jQuery selector.

A big thanks goes out to my friends,Alex Olson & Sam Curren, for helping me understand my mistake while being tired.

If I didn’t need to do something different for each time through the loop I could do something like this stack overflow answer:

array = ["h1","p","div"];
console.warn( $K( array.join(", ") ).children() );

ie error expected identifier string or number

ie error expected identifier string or number

ie error expected identifier string or number

IE 7 was throwing an error while working on some JavaScript

ie error expected identifier string or number

The problem was that I had an extra comma in a hash

this.css({
      "position":"fixed",
      "top": ( $K(window).height() - this.height() ) / 2 + "px",
      "left": ( $K(window).width() - this.width() ) / 2 + "px",
    });

It should have been

this.css({
      "position":"fixed",
      "top": ( $K(window).height() - this.height() ) / 2 + "px",
      "left": ( $K(window).width() - this.width() ) / 2 + "px"
    });

Photo: By stealingsand

jQuery vs Flash

jQuery_vs_Flash

In the fight of jQuery vs Flash there are many arguments on both sides but I think this smart bird sums it up nicely. ; )

Twitter on my blog

jQueryI finally made enough time to put a twitter feed on my blog and man does it feel good to have that done. I found a fun jQuery based widget called Juitter that can be found at http://juitter.com/

I changed some of the functionality and the css in the jQuery functions so it would be a little more compacte and now it is looking great. Really easy to install but if you are wanting to customize it beyond how many tweets show up you are going to need a fair understanding of jQuery.

Reblog this post [with Zemanta]