开发者

after jQuery upgrade, uncaught exception: Syntax error, unrecognized expression: h3

开发者 https://www.devze.com 2023-01-15 09:05 出处:网络
I\'m working on a new version of the website, and am now finding an i开发者_如何学Pythonssue with my javascript code that isn\'t being handled nicely.

I'm working on a new version of the website, and am now finding an i开发者_如何学Pythonssue with my javascript code that isn't being handled nicely.

What I have been doing in the past is

$('#lb_outer_title :h3').html(title); 

which changed the text of the title attribute for my lightbox. This worked fine in jQuery 1.3.2, but on the new version (which is using jQuery 1.4.2) I get the error:

uncaught exception: Syntax error, unrecognized expression: Syntax error, unrecognized expression: h3

In the new version I can change the code to the following and it works, but this can't be the optimal solution:

$('#lb_outer_title').html('<h3>'+ title + '</h3>');

I've tried the using :first selector in my new version, but that doesn't work as desired either.

Here is the html that I'm working with (note: I can't add class or id to the h3 tag):

 <div id="lb_outer_title">
   <h3>Title</h3>
  </div>


Your mistake is here:

$('#lb_outer_title :h3').html(title); 

That colon before the h3 should be dropped. jQuery 1.4 has a stricter selector engine and that's why it's reporting your error (since you're using a pseudo-class prefix on an element selector), while jQuery 1.3 merely silently parses the colon away.


$('#lb_outer_title h3').html(title); 

Not sure what that colon was doing in there... It is not a valid selector. : is used for psuedo-classes, but you simply want an element.


Just remove the : like this:

$('#lb_outer_title h3').html(title); 

The colon prefix, :, is used for various pseudo selectors, you just want h3, the element selector.

0

精彩评论

暂无评论...
验证码 换一张
取 消