Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23104

Re: Jquery/Javascript TOC

Message-ID <3163707.iqS82ShrHT@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2014-02-16 03:04 +0100
Subject Re: Jquery/Javascript TOC
Newsgroups comp.lang.javascript
References <bad9ad8b-51f4-4cfe-a841-fb6043aafe7f@googlegroups.com>

Show all headers | View raw


luca.saracino@gmail.com wrote:

> Hi, I'm trying to put in place a nice Javascript/jQuery plugin index
> within a wordpress page:
> http://css-tricks.com/automatic-table-of-contents/
> 
> No way for me to make this working! I get these errors:
> Mozilla console: SyntaxError: missing ; before statement
> Chrome console: Uncaught SyntaxError: Unexpected identifier
> 
> var ToC =
>   '<nav role='navigation' class='table-of-contents'>' +
> -> error here <------------
> ....

Actually, the syntax error is after the second apostrophe already.  You must 
not use the apostrophe both for the script string delimiter and the 
attribute value delimiter, at least not an unescaped attribute delimiter: 
the script engine will consider the string literal to have ended where your 
attribute value begins.  Likewise for double-quotes.

> someone suggest to modify by this but same results:
> '<nav role="navigation" class="table-of-contents">' +

Exactly.  However, depending on what precedes this code and what follows the 
plus operator (which means string concatenation here), the program could 
still be syntactically in error.
 
> Also checked with vim if any hidden or special characters in my html but
> the only one found were normal carriage return symbolized with "$"
> character.

Last I checked, Vim did not use “$” to represent <CR>, but a differently 
(blue, as compared to the default light-gray) colored “^M”.  Your Vim might 
be configured to mark the end of a line with “$”; that is a different thing.

> Have tried same code copied and pasted roughly from the tutorial above and
> works nicely here: http://jsfiddle.net/zEvJ5/ and here
> http://codepen.io/chriscoyier/pen/EnLwb

Well, the programs presented there are not syntactically in error.  Also, 
the example uses double-quotes as string delimiter and apostrophes as 
attribute delimiter, which might be significant (depending on how cluelessly 
the generator was programmed).

That said, it is of course a stupid idea to have the table of contents of a 
document generated dynamically *client-side*: what about search engines, 
what about users in whose user agents the script is not executed for various 
reasons?

> many "mini" jQuery plugs works fine like this one:
> <script>
> $(document).ready(function(){
>   $("p").click(function(){
>     $(this).hide();
>   });
> });
> </script>
> 
> Don't really know what's wrong! If anyone can makes this working, I would
> be really curious to know how has it done!

Struggling with basic ECMAScript syntax already, you should refrain from 
using libraries until you have gotten a minimum clue about the programming 
languages you are using.  That said, you should avoid jQuery anyway.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Jquery/Javascript TOC luca.saracino@gmail.com - 2014-02-15 14:56 -0800
  Re: Jquery/Javascript TOC Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-16 03:04 +0100
  Re: Jquery/Javascript TOC Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2014-02-16 18:59 +0100
    Re: Jquery/Javascript TOC luca.saracino@gmail.com - 2014-02-16 10:52 -0800

csiph-web