dianefoster Posted December 3, 2016 Share Posted December 3, 2016 <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> #h1 { color: #000000; } </style> </head> <body> <h1 id ="h1">Discover Australia</h1> </body> </html> "use strict"; function changeColour() { var heading = ["Discover"]; for(var i =0;i<heading.lenght;i++) { heading = heading.split(" "); heading = heading.charAt(0).style.fontColor = "#F00"; heading = heading.charAt(1).style .fontColor = "#F00"; heading = heading.subString.style.fontColor = "#000"; } var result = heading.join(" "); console.log(result); } document.getElementById("h1").addEventListener("onload", changeColour,false); Link to comment Share on other sites More sharing options...
dsonesuk Posted December 3, 2016 Share Posted December 3, 2016 The second letter needs to be pre wrapped in a element such as span, you can't apply colour to any letters other than the first letter, where you can use css :first letter, OR using JavaScript you copy 2nd letter place in between span and replace 2nd character with span wrapped 2nd letter. always style with css by referencing span class. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now