I'm trying to do something that would be similar to turning a url slug-like variable into text that could be used for a title.
So, I have a variable for example that is like this:
var thisID = 'athlete-profile'; function myFunc(thisID) { // i need to use thisID as the id and href in a loop that generates a string of <li><a>'s\ function makeTitle(thisID) { // convert thisID to text so for this example it would return 'Athlete Profile' return 'Athlete Profile'; } for () { var str = '<li id="'+thisID+'"><a href="#'+thisId+'">'+makeTitle(thisID)+'</a>'; } // make sense? } I'd like to not use a regex to do this if possible somehow, but I don't think there's a way to do it without one. So any one who knows how to do this type of thing let me know, it would be a great help.
Thanks
forloop doing? Element ids need to be unique, so you shouldn't be creating elements in a loop and giving them all the same id.thisID.replace(/-/g, " ")(as shown in the first part of my answer). But doing the capitalisation is also easy as shown in any of the answers below.