문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top