Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQuery execution

 
William Rouse
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is the source listing of a tutorial on construction sequential parts of a form using jQuery. In studying the tutorial I realized that there is a significant non understanding that I have of jQuery. The problem is the appearance and disappearance of the next and previous prompts in the first and last section of displaying the form. When I step through the code with a debugger, the debugger never hits either of these two functions,

yet the proper prompts appear. Can someone explain this? Thanks!
WBR



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Rouse wrote:When I step through the code with a debugger, the debugger never hits either of these two functions

The two lines you show are part of the document-ready handler and cannot possibly not be called. I suspect your debugger isn't getting control until after they have executed.
 
William Rouse
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After the page is plotted and someone is filling in the form on the second section, and then either moves forward to the third page, or backward to the first page, should not one of these functions be executed.
WBR
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't they be called? If I set a breakpoint on the remove() lines the breakpoint is hit (FF/Firebug).

It's working for me (although I'd argue against doing it like this).
 
William Rouse
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using the javascript debugger in Netbeans and I don't see it. I'll try learning enough of Firebug later and try it.
David Newton, how would you go about it?
Thanks!
WBR
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering the low number of inputs I'd just put it all on one page. If there was some compelling reason to break it up I'd just use new pages. I don't feel the JS hide/show functionality adds anything.

If I *was* going to do it like this I'd figure out some way to make it less brittle. Seeing things like "$(this).parent().parent().hide().next().show();" tells me that it'll break at some point from an unrelated structural change--and if the person fixing it isn't the person that wrote it they'll be sad.

Oh, and always use "for" attributes on label tags :p
 
William Rouse
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just a tutorial someone presented to show a concept and I learned from it.
I don't understand though, David what you mean by "label tags :p", where in the code is that?
Thanks!
WBR
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to agree and disagree with David.

I prefer clarity over cleverness, so yeah, I wouldn't do things exactly this way. But this is from a tutorial where often "cleverness" is used just to get a concept across. Out of context, it's hard to tell.

I would not discount using dynamic elements, but again, I'd do it in a clearer fashion than is done here.

Also, the mere presence of long chains of jQuery commands isn't an issue -- in fact, it's one of jQuery's great strengths. But yes, I'd do things in a less fragile fashion. Long command chains aren't something to be avoided; just something to be sure to do well.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Rouse wrote:what you mean by "label tags :p", where in the code is that?

There are label tags in the HTML markup. Some have for attributes, but some do not.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not against train wrecks, but (largely) structural ones give me the willies. Being Smalltalkish I'm a big fan of chaining :)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:but (largely) structural ones give me the willies.

Agreed. Too fragile for my tastes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic