javascript - Issue with capitalizing innerHTML text -
i working on project html class , wasn't able figure out how capitalize first letter of text replaced image during onmouseover event, which, in turn, returned initial picture state during onmouseout event. able make text show up, can't first letter capital. text supposed link (href, not href, in order prevent page going link if "cancel" hit on confirm box popped when clicked). confirm box pops asking if want go link, if not, when hit cancel, page stays.
this function:
function planetname(x,y,z){ document.getelementbyid(x).innerhtml=y; document.getelementbyid(x).style.backgroundcolor="clear"; document.getelementbyid(x).style.color="white"; document.getelementbyid(z).style.height="172px"; } in case, x href link, y planet name , z table row in. here part of html:
<h3>click on 1 of images below learn more planet.</h3> <table height="150px" id="tabl"> <tr id="tr1"> <td onmouseover=planetname("mercurylink","mercury","tr1") onmouseout=planetpic("mercury","mercurylink","tr1")><href="mercury.htm" onclick=page("mercury") id="mercurylink"><img src="images/mercury.png" height="150px" id="mercurypic"></td> <td hidden id="mercury">mercury</td> </tr> there no issue onmouseout or onclick, onmouseover giving me issue.
thanks lot.
for capitalization problem propose this:
document.getelementbyid(x).innerhtml = y.substring(0,1).touppercase() + y.substring(1).tolowercase(); first extract first letter , capitalize , make sure rest in lowercase.
Comments
Post a Comment