Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2010, 10: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().
 
Old August 4th, 2010, 11:09 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
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?
 
Old April 30th, 2011, 03: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.
 
Old April 30th, 2011, 03:40 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
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?
 
Old April 30th, 2011, 03: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.
 
Old May 1st, 2011, 04:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
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?





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 10:48 AM
Very general question merianos VB How-To 4 August 1st, 2006 12:24 PM
General Question stu9820 ASP.NET 1.0 and 1.1 Basics 2 September 23rd, 2003 03:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.