2

This is follow up question.

The first selector which is fully typed out finds the value all the others give a syntax error even though they "look" identical.

    $(".smoothie").on("mouseover", function(event) {
          // .. other code

            // first    
            value = $(".row_2.tuesday .e_1.current_Status .smoothie_Text").attr("value");
            alert(value);

            // second
            selector = "\'.row_2.tuesday .e_1.current_Status .smoothie_Text\'";
            alert(selector);
            value = $(selector).attr("value");

            //third
            value = $("\"." + row_Classes[0] + "." + row_Classes[1] + " ." + container_Classes[0] + "." + container_Classes[1] + " .smoothie_Text\"").attr("value");
            alert(value);
          //.. other code
}).svg({loadURL: '../_public/_icons/smoothie.svg'});    

Could some one please advise what I am doing wrong.

Edit

Error from console is:

Error: Syntax error, unrecognized expression: ' [Break On This Error]

throw new Error( "Syntax error, unrecognized expression: " + msg );

Which we know from yesterdays enquiries is from sizzle.

4
  • They are not identical, second and third selectors have surrounded by quotes. You shouldn't use quotes around selectors. Commented Dec 6, 2012 at 10:03
  • 1
    why are you escaping quotes in strings? Commented Dec 6, 2012 at 10:03
  • @tborychowski A better question is why the quotes are there at all. The third example does in fact legitimately require escaping of the quotes. Commented Dec 6, 2012 at 10:06
  • Ok I was getting in a mess thinking I needed the quotes to complete the selector on the basis that $("#someid .someclass").dosomething is the normal syntax so I was adding them in when constructing the selector. Commented Dec 6, 2012 at 10:14

3 Answers 3

3

Both your second and third strings contain quotes at the ends. Selectors are not supposed to contain quotes at the ends. It is that simple.

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

1 Comment

Yes looking at this for to long got in a mess. Couldn't see why. Thanks.
3

try it by removing \' , so it should be like as below

// second
selector = ".row_2.tuesday .e_1.current_Status .smoothie_Text";

there is no need of the \' in your selector code

Comments

0

try remove slashes \ and single quotes '

        selector = ".row_2.tuesday .e_1.current_Status .smoothie_Text";
        alert(selector);
        value = $(selector).attr("value");

        //third
        value = $(row_Classes[0] + "." + row_Classes[1] + " ." + container_Classes[0] + "." + container_Classes[1] + " .smoothie_Text").attr("value");
        alert(value);

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.