Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning JavaScript and CSS Development with jQuery
This is the forum to discuss the Wrox book Beginning JavaScript and CSS Development with jQuery by Richard York; ISBN: 9780470227794
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript and CSS Development with jQuery section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old August 4th, 2010, 11:32 AM
skr skr is offline
Registered User
 
Join Date: Aug 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default slice()

Although I do not want to get into a semantics discussion regarding the parameters of slice(), I would think that it would be akin to javascript substring(starting Index, ending Index) but rather it appears to be similar to substr(starting Index, length) both zero referenced. The definition on page 452 seems to indicate parameters similar to substring().
Reply With Quote
  #12 (permalink)  
Old August 4th, 2010, 12:09 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Yes, I agree, the text and appendix are misleading, but the code is correct.

It is in fact identical to substring, but a bit counter intuitive.

"Hello World".substring(0,4) = "Hell"

i.e. the first four items, exactly like in the example in the book.

You need to think of the index being positioned in the spaces between the letters, instead of referring to a specific letter for each index.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #13 (permalink)  
Old April 30th, 2011, 04:21 PM
Registered User
 
Join Date: Apr 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selection Syntax

Just bought the book and have found what seem to be some minor errors. Will post later. But I'm reading front to back. Best resource for jQuery development that I've seen. Congratulations on a great and very high quality book.

But first a question on $(selector) syntax:

Why use $(div#mydiv) when $(#mydiv) is correct syntax according to the jQuery API?

Clearly the leading 'div' is redundant since, by definition, mydiv can only refer to one element.
Reply With Quote
  #14 (permalink)  
Old April 30th, 2011, 04:40 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Generally #mydiv will I think be slightly faster. But when you say "by definition" mydiv can only refer to one element, what definition are you referring to? There is nothing to stop someone giving the same ID to two elements - they are just attribute values. (Doesn't mean it would be valid HTML however).
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #15 (permalink)  
Old April 30th, 2011, 04:49 PM
Registered User
 
Join Date: Apr 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default You can do it but ...

But $() will only select the first one it finds. ID is not .class.
Reply With Quote
  #16 (permalink)  
Old May 1st, 2011, 05:50 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

That's true.

I think whichever you find easier to read is the most important thing. As the jquery docs state:

Quote:
As always, remember that as a developer, your time is typically the most valuable resource. Do not focus on optimization of selector speed unless it is clear that performance needs to be improved.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
General Question about the beerhouse example kss BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 26th, 2008 12:08 PM
General SELECT question rsearing SQL Server 2005 1 January 16th, 2007 12:01 PM
General Question About c++ madeebmir C++ Programming 0 August 15th, 2006 11:48 AM
Very general question merianos VB How-To 4 August 1st, 2006 01:24 PM
General Question stu9820 ASP.NET 1.0 and 1.1 Basics 2 September 23rd, 2003 04:36 PM



All times are GMT -4. The time now is 10:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.