3

I have this problem with Jquery items[c] is well defined as HTMLElement but when I use .find with more than one selector I get this error:

TypeError: X[g].exec is not a function
http://code.jquery.com/jquery-latest.min.js

when i checked some watches i got what is in the image below:

$(items[c]).find('.received') works fine and returns some elements as there is elements with that class

$(items[c]).find('.receive') works fine too and returns zero elements as there is no elements with that class.

but $(items[c]).find('.received.unseen') returns undefined and bugs. so what is happening here?

enter image description here

EDIT: here is what is inside items[c], from the debugger firefox enter image description here

EDIT: here is the function where i have the bug and i switched to jquery 2.1.1:

function updateUnseenBell(){
    var m;
    for (var c in items)
        if (items.hasOwnProperty(c) && (m = items[c].gEbCN("chat-partner-tab")[0])) {
        if($(items[c]).find('.received.unseen:not(.shown)').length > 0){
            if (!(m.l2_newMsgBell)) {
                m.appendChild(m.l2_newMsgBell = newMsgBell.cloneNode());
                playSound("message");
            }
        } else if (m.l2_newMsgBell) {
            m.removeChild(m.l2_newMsgBell);
            delete m.l2_newMsgBell;
        }
    }
}

and i reduced it to this minimum for debug but still get the same error:

function updateUnseenBell(){
    for (var c in items) {
        if (items.hasOwnProperty(c)) {
            if ($(items[c]).find('.received.unseen:not(.shown)').length > 0) {
                alert(1);
            } else {
                alert(2);
            }
        }
    }
}
14
  • 1
    can you add html mark up? is element .received and .unseen same or child?if child just add space between them Commented Sep 19, 2016 at 3:45
  • 1
    further to @guradio - if you are targetting multple selectors (ie not child) you need a comma between them ... $(items[c]).find('.received, .unseen').... Commented Sep 19, 2016 at 3:47
  • 1
    I cannot reproduce this (besides, I'm pretty sure .find handles compound selectors just fine). Commented Sep 19, 2016 at 3:51
  • 1
    What is items[c]? what does it contains? Please log it and post it Commented Sep 19, 2016 at 3:52
  • @guradio thank you. no they are classes for same element so there should not be a space in fact my finale purpose is to use this $(items[c]).find('.received.unseen:not(.shown)'). to select all elements in items[c] that have received and unseen classes but not shown. but it does not work even with just ('.received.unseen') Commented Sep 19, 2016 at 3:55

2 Answers 2

8

Use

$(items[c]).find('.message.received.unseen') 

and that should work.

One other way to solve this will be

$(items[c]).find(".received").find(".unseen").find(":not(.sh‌​own)")

Its not an elegant approach but works too.

Sign up to request clarification or add additional context in comments.

6 Comments

i have tried that but it does not work. item misses an s btw.
yes thank you i managed to get the full functionality (with :not(.show)) too on the site, and it works fine here .. so I don't know what i'm missing in my code. i posted the function above in the edit.
inside theif (items.hasOwnProperty(c)) { if you do console.log(items[c]) do you get what you attached as an image. Also what does items contain.
yes i get the right object. i even added var a = items[c]; which i use after: ($(a).find(".received.unseen:not(.shown)"); but still the same.
try var a = $(items[c]).not(":visible"); and then $(a).find(".received.unseen:not(.shown)". It also works in the fiddle. jsfiddle.net/y8tfeuy1/3
|
0

Another approach you can use:

$(items[c]).find(".received, .unseen, :not(.sh‌​own)");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.