pranav thakur
pranav thakur

Reputation: 41

Javascript:Change class and title on click

On clicking the number should change the class and title from not_viewed to viewed making color change from red to green .But obviously,it is not working as no color change is occuring.

Html

<span title="not_viewed" class="not_viewed" id="1" onclick="javascript:changeclass()">1</span>
Javascript
function changeclass() {var NAME = document.getElementById("1"); NAME.className = "viewed" NAME.title="viewed"
  < /script>
}

css

span.viewed{color:green; }
span.not_viewed{color:red;}
span{cursor:pointer;}

See http://jsfiddle.net/yKbFk/1/

Upvotes: 0

Views: 85

Answers (2)

Exception
Exception

Reputation: 8379

Remove < /script> tag from function.

Check it here http://jsfiddle.net/yKbFk/6/

Upvotes: 1

MrCode
MrCode

Reputation: 64526

Remove < /script> from within the function, because it's causing a syntax error:

Uncaught SyntaxError: Invalid regular expression: missing /

Demo

Remember to check the console (F12) for errors to make debugging easier for yourself.

Upvotes: 1

Related Questions