Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to just bold and underline the (anchor) link when it was clicked with the help of jquery....But didn't know of how to do it.... Here is my code:
ASP.NET Syntax (Toggle Plain Text)
HTML
  <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("a").click(function () {

                alert("Hello");

                //                $('.body_text').css('width', '100px');
                //                $('.body_text').css('text-decoration', 'underline');
                //                //this.addClass('makebold');
                //$(this).toggleClass('makebold');
                $(this).css({ "text-decoration": "underline","font-weight": "bold" });
                //$(this).removeClass('makebold');
                //The above code doesn't show this alert is there anything wrong in //writing it as:$('.body_text a').......
                //Some magical code here to bold and underline the selected anchor link //only...
            });
        });
    </script>

<div class="body_wrapper">
    <div id="body_header">
        <div id="body_header_contents_Employees">
            <table cellspacing="18">
                <tr >
                    <td align="center" class="body_text"><a  href="Add_Employee.aspx"><img src="../images/body_header_images/iconEmployees.gif" alt="Add_Employee" title="Add_Employee" border="0" /><br />Add Employee</a></td>
</tr>
</table>
</div></div></div>

The remaining problem is when I use this code and hit the anchor it shows an alert box of hello and makes itself bold and underline too for a fraction of seconds and as soon as the page reload or goes to the href of the anchor all the decoration becomes void.....even if the anchor refer to the same page the decoration becomes void tooo.
what is to be done on page refreshes.............and maintain the decoration of text on it
Posted
Updated 11-Jan-12 5:16am
v2

1 solution

You understand the web is stateless, correct? When you are clicking on the link the specified resource, even if the same page, is loaded as if being visited for the first time. Unless told the browser has no way of know this is the first visit or the 15th. The CSS pseudo class visited[^] will tell if the link has been previously clicked. You can change the look of such links with CSS, you don't need to use JQuery.
 
Share this answer
 
Comments
Mohammad Azeem 11-Jan-12 13:58pm    
@Marcus Kramer so plz tell me some sort of solution to fix this problem as the visited is not suitable for this condition
[no name] 11-Jan-12 15:14pm    
You have the information needed to answer this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900