MyRevenge
MyRevenge

Reputation: 117

Automatic id on tags

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.

Upvotes: 0

Views: 169

Answers (1)

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382274

$('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 (".").

Upvotes: 1

Related Questions