...

View Full Version : help! how to make text help: how to make text boldbold



lovesirius12
08-25-2008, 04:27 AM
<td width="150"><div align="center"><a href="" onclick="this.style.fontWeight = 'bold';">item 1 </a></div></td>

i have the code above to make the font of the clicked link to be bold, but it goes back to being normal and doesnt stay to bold font state.

thanks.

rhinodog8
08-25-2008, 05:03 AM
add onmouseup="this.style.fontWeight = 'bold';"

thats my guess, keep the onclick function too.

lovesirius12
08-25-2008, 05:18 AM
add onmouseup="this.style.fontWeight = 'bold';"

thats my guess, keep the onclick function too.

thanks, but it still doesnt solve the problem.

rhinodog8
08-25-2008, 05:37 AM
is there a reason you have the text in <a></a> tags? your href doesn't link to anything. trying using <span></span> tags and see if it fixes it, because when you click a link(<a></a>) it reverts to a certain state.

lovesirius12
08-25-2008, 06:26 AM
<td class="page" onclick="this.style.fontWeight = 'bold'; alert('item 1'); "width="200"><div align="center" ><a href="#" >item 1 </a></div></td>


i changed it to the above, and it retains the bold property. now, do you have any idea how can i return it normal when i click other link?

thanks again,

Arbitrator
08-25-2008, 06:32 AM
your href doesn't link to anything.href="" is a document self‐reference; it links to the current document.


<td width="150"><div align="center"><a href="" onclick="this.style.fontWeight = 'bold';">item 1 </a></div></td>

i have the code above to make the font of the clicked link to be bold, but it goes back to being normal and doesnt stay to bold font state.As I just told rhinodog8, href="" links to the current document. Thus, when you click it, it should be reloading the current document. This would reset your script and cause the a elementís text to return to its default state.

You need to either remove the href attribute or cancel its default action. The latter can be done with (reusable) code like the following:


<!--[if !IE]>-->
<script type="application/ecmascript">
function PDA(event) { // PDA: Prevent Default Action
event.preventDefault();
}
</script>
<!--<![endif]-->
<!--[if IE]>
<script type="text/ecmascript">
function PDA(event) { // PDA: Prevent Default Action
window.event.returnValue = false;
}
</script>
<![endif]-->


<a href="" onclick="PDA(event); this.style.fontWeight = 'bolder';">Google</a>

Personally, I would just remove the attribute.

rhinodog8
08-25-2008, 06:34 AM
i don't know for sure, you could try adding this to the second link that will revert the other link to normal
onclick="getElementByName('table').set.style.fontwieght = 'normal'; "

add a name="table" to the orginal table you wanted reverted back.

Arbitrator
08-25-2008, 06:38 AM
i changed it to the above, and it retains the bold property. now, do you have any idea how can i return it normal when i click other link?Give the element with the onclick event listener (td in your latest code) an id attribute (e.g., <td id="my_ID">). Then use something like <a onclick="PDA(event); document.getElementById('myId').style.fontWeight = 'normal';">Anchor Text</a>. (The PDA functions were defined in my last post.)

Arbitrator
08-25-2008, 06:49 AM
i don't know for sure, you could try adding this to the second link that will revert the other link to normal
onclick="getElementByName('table').set.style.fontwieght = 'normal'; "

add a name="table" to the orginal table you wanted reverted back.That would be something more like onclick="document.getElementsByName("table").item(0).style.fontWeight = 'normal';" assuming that there was only one element with the name attribute value table or the desired element in a group of such elements is the first in the documentís DOM. (In the revised code, note the document. part, that the Elements part of the method name is plural, that itís followed by item(0) (or [0]) rather than .set, and that fontWeight is camel case with a different spelling than you typed. Maybe these were all just typos though.)

Personally, I would stick with IDs over names since you only have to deal with one element rather than an array of them. The name attribute is formally deprecated outside of form usage anyway.

lovesirius12
08-25-2008, 07:49 AM
thanks for all the help. i tried everything you suggested. but it still doesnt work :( sorry.

lovesirius12
08-25-2008, 08:35 AM
got it!!

<script type="text/javascript">
function makeitNorm(){
var emNodes = document.getElementsByTagName('td')
var max = emNodes.length
for(var i = 0;i < max;i++)
{
var nodeObj = emNodes.item(i)
nodeObj.style.fontWeight = 'normal';
}
}
</script>

<td class="page" onclick="makeitNorm(); this.style.fontWeight = 'bold'; alert('item 1'); " width="200"><div align="center" ><a href="#" >item 1 </a></div></td>
</tr>

it now works!! thanks for all your help. i got bits and pieces from each and everyone. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum