Domanda

I´ve got this script:

JS

$("#content div.nav").each(function() {
   $(".navi ul").append('<li><a href="#'+ $(this).attr("id") + '">' + $(this).attr("id") + '</a></li>');
});

It generates out of ID´s a navigation, but sometimes I´ve got a ID with a space for example "Agen da" and with such an anker the script doesnt scroll, can you help me with that?

Fiddle

http://jsfiddle.net/RDFf9/14/

È stato utile?

Soluzione

Let's make it work with spaces :)

Create your divs like this:

<div title="Location 3" id="Location3" class="nav">

Remove the spaces in your id's then add title attribute which can have spaces.

Then have your script like this:

$("#content div.nav").each(function() {
    $(".navi ul").append('<li><a href="#'+ $(this).attr("id") + '">' + $(this).attr("title") + '</a></li>');
});

Notice that I replaced the second id with title

Check the demo Here

Hope it helps

Altri suggerimenti

HTML element ID's can not have spaces.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top