Frage

Hello i'm building a side with a local scroller. Is there any way i can take the value of my tag and use that as id.

<h2>test</h2>

so it would be like this

<h2 id="test">test</h2>

I'm running wordpress.

War es hilfreich?

Lösung

$('h2').each(function(){
   this.id = $(this).text();
});

But beware that not all characters are allowed in an id :

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top