<%= link_to_remote>,Change Hyperlink Text Color Onmouseclick
I need to change the clicked hyperlink text's color when clicking on it, that is part of a div. There are many hyperlinks in the same div,开发者_JAVA技巧 as below:
<div id="link"<br>
<b>Period:</b>
(<%= link_to_remote "Today", :url =>{:action =>'period_list',:period=>"today"},:onmouseclick=>"changeColor(this,'#FF0000');"%>/
<%= link_to_remote "This week", :url =>{:action =>'period_list',:period=>"weeks"}%>/
<%= link_to_remote "This month", :url =>{:action =>'period_list',:period=>"months"}%>
</div>
in <head>
the code below is given:
<script type="text/javascript" language="javascript">
function changeColor(idObj,colorObj)
{
document.getElementById(idObj.id).style.color = colorObj;
}
</script>
but, after clicking on 'today', the text color will not change.
Can you please give a solution to solve this.
thanks...
You don't give ID to the link, so idObj.id return blank string and document.getElementById(idObj.id)
returns NULL.
To fix this have such code instead:
idObj.style.color = colorObj;
精彩评论