Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQuery Selector issue

 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Why is the alert not showing up on click of Java Test 1 in the code sample below? Is my selector syntax not correct? I guess so...

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your selector is overly complicated. this will suffice:



If you want to limit it to anchor children of paragraphs:



Demo
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:Your selector is overly complicated. this will suffice:



If you want to limit it to anchor children of paragraphs:



Demo


Before asking for help here, I tried both of the options that you had mentioned. It seems not to show the alert. Popup blocker is deactivated on my browser. Bemused why the alert is not coming up.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try the demo link I provided? Does it also not work? What browser and what version of jQuery are you using?
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm attaching a screenshot of the page that contains this href
jQuery_href.png
[Thumbnail for jQuery_href.png]
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The demo seems to work, but why not on my machine? I use firefox 4.0. Has it got anything to do with the other jQuery functions that I have in my page?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:The demo seems to work, but why not on my machine? I use firefox 4.0. Has it got anything to do with the other jQuery functions that I have in my page?



Try your local copy without the extra stuff (like your UI .tabs() function) and see what happens.

Use a tool like Firebug to inspect the elements after jQuery UI has gotten hold of everything and see if the markup was changed in a way that would cause the selector to stop working.
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I did use Firebug to find out what gets rendered. Here it is:



Looks like the selector should work
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The entire html body after rendering:

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, seems like it should. Did you attempt it without rendering the UI tabs? Also, try adding a class to each anchor and use that as the only selector and see if it works. Get as specific as you can with your selector.




 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:Yep, seems like it should. Did you attempt it without rendering the UI tabs? Also, try adding a class to each anchor and use that as the only selector and see if it works. Get as specific as you can with your selector.






Did not work as well.

Here, again the complete html.

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just noticed that your binding to the click event is happening outside of jQuery's ready function. That's probably why it isn't working for you.
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spot on. Thanks for the suggestion. But can't a page have more than one ready function? I thought I have have as many as I wish on my page.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, a page can have as many ready handlers as you like.
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with the following snippet?



The backAnch does not get triggered?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there elements with the backAnch class?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic