This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes jQuery Selector issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jQuery Selector issue" Watch "jQuery Selector issue" New topic
Author

jQuery Selector issue

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

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...



SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Your selector is overly complicated. this will suffice:



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



Demo

GenRocket - Experts at Building Test Data
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

I'm attaching a screenshot of the page that contains this href


[Thumbnail for jQuery_href.png]

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

Yes, I did use Firebug to find out what gets rendered. Here it is:



Looks like the selector should work
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

The entire html body after rendering:

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Jan 10, 2002
Posts: 61071
    
  66

Yes, a page can have as many ready handlers as you like.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

What is wrong with the following snippet?



The backAnch does not get triggered?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61071
    
  66

Are there elements with the backAnch class?
 
Consider Paul's rocket mass heater.
 
subject: jQuery Selector issue