Give help. Get help.

  • # March 6, 2013 at 6:15 pm

    I have a list of items like this:

    Fight club
    Life of Pi

    and I want to put all the elements in an array and loop through them but just the items with the class `element` without their children.

    elements = $(“#content”).children(‘.element’);

    but it gives the right length of array but its index contains the element with its children and I can’t `addClass` for example, gives me an error. It drives me crazy….

    # March 6, 2013 at 8:01 pm

    I don’t get it. With its children? I think it’s more the issue that `$(…)[0]` gives you a node object instead of a jQuery object. Try `$(…).eq(0)` instead.

    # March 6, 2013 at 8:58 pm

    @CrocoDillon check this simple [jsFiddle]( “”) and the comments. I can select an element with a click function but I want also to be able to select elements using they keyboard keys. In this example I try to select just the first element pressing any key.

    note: in order for keydown function to work result window should be active by clicking anywhere in it. Also check the logs on the console.

    # March 6, 2013 at 9:55 pm

    `searchElements.eq(0).addClass(‘selected’);` or `$(searchElements[0]).addClass(‘selected’);`, I need sleep. If you need any more help I’ll be back tomorrow!

    # March 6, 2013 at 10:33 pm

    no worries, with your latest comment I understood what I was doing wrong. Time for me to sleep also. Thanks

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.