Skip to content
Advertisement

Remove space or replace with underscore of auto generated ID tags

Completely revising my question.

I am using this code to generate an id tag:

JavaScript

Which produces this html:

JavaScript

I cant have a space in the id. I need to either remove it on replace it with an underscore.

Is there a way to accomplish this?

This did not work:

JavaScript

Thanks to Nico Bleiler for pointing out my original code errors!

Advertisement

Answer

For the anchor to work properly the fragment in url has to be identical to the id of the element.

JavaScript

If you click it it will update the URI fragment and scroll to the element on the page that has the id

JavaScript

Use the method urlencode ( string $str ) : string on your variable like

JavaScript

and encode the a tags yourself to match them

I inspected your a tags.

It seems like you used the wrong apostrophe.

The Browser updated your example and corrected it

<a href="“#Craft_Cocktails”">Craft Cocktails</a>

You mixed and "

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement