Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  103] [ 2]  / answers: 1 / hits: 29369  / 13 Years ago, fri, february 3, 2012, 12:00:00

I have a line of code which is...



<div class=x>
xyz
</div>


I want to write a script to find the div where class == x, and change it to be...



<div class=x id=y>
xyz
</div>


any help is appreciated


More From » jquery

 Answers
128
// Without jquery
document.querySelector('div.x').id = 'y';

// With jquery
$('div.x').attr('id', 'y');

[#87656] Thursday, February 2, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tajo

Total Points: 415
Total Questions: 124
Total Answers: 103

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
;