Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2005
    Location
    Laguna, Philippines
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help! how to make text help: how to make text boldbold

    <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.
    "It is the unknown we fear when we look upon death and darkness, nothing more!"-- Albus Dumbledore

  • #2
    New Coder
    Join Date
    Aug 2008
    Location
    Colfax, California USA
    Posts
    64
    Thanks
    3
    Thanked 5 Times in 5 Posts
    add onmouseup="this.style.fontWeight = 'bold';"

    thats my guess, keep the onclick function too.

  • #3
    New Coder
    Join Date
    Aug 2005
    Location
    Laguna, Philippines
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rhinodog8 View Post
    add onmouseup="this.style.fontWeight = 'bold';"

    thats my guess, keep the onclick function too.
    thanks, but it still doesnt solve the problem.
    "It is the unknown we fear when we look upon death and darkness, nothing more!"-- Albus Dumbledore

  • #4
    New Coder
    Join Date
    Aug 2008
    Location
    Colfax, California USA
    Posts
    64
    Thanks
    3
    Thanked 5 Times in 5 Posts
    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.

  • #5
    New Coder
    Join Date
    Aug 2005
    Location
    Laguna, Philippines
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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,
    "It is the unknown we fear when we look upon death and darkness, nothing more!"-- Albus Dumbledore

  • #6
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,274
    Thanks
    28
    Thanked 271 Times in 265 Posts
    Quote Originally Posted by rhinodog8 View Post
    your href doesn't link to anything.
    href="" is a document self‐reference; it links to the current document.

    Quote Originally Posted by lovesirius12 View Post
    <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:

    Code:
    <!--[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]-->
    Code:
    <a href="" onclick="PDA(event); this.style.fontWeight = 'bolder';">Google</a>
    Personally, I would just remove the attribute.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #7
    New Coder
    Join Date
    Aug 2008
    Location
    Colfax, California USA
    Posts
    64
    Thanks
    3
    Thanked 5 Times in 5 Posts
    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.

  • #8
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,274
    Thanks
    28
    Thanked 271 Times in 265 Posts
    Quote Originally Posted by lovesirius12 View Post
    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.)
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #9
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,274
    Thanks
    28
    Thanked 271 Times in 265 Posts
    Quote Originally Posted by rhinodog8 View Post
    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.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #10
    New Coder
    Join Date
    Aug 2005
    Location
    Laguna, Philippines
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for all the help. i tried everything you suggested. but it still doesnt work sorry.
    "It is the unknown we fear when we look upon death and darkness, nothing more!"-- Albus Dumbledore

  • #11
    New Coder
    Join Date
    Aug 2005
    Location
    Laguna, Philippines
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    "It is the unknown we fear when we look upon death and darkness, nothing more!"-- Albus Dumbledore


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •