1

I'm using javascript (and jQuery) to move between three box descriptions.

Javascript

<script type="text/javascript">
    $(document).ready(function() {
        $('#foo-box').show();
        $('#bar-box').hide();
        $('#bob-box').hide();

      $('#bar-link').click(function() {
        $('#foo-box').hide();
        $('#bob-box').hide();
        $('#bar-box').show();
         return false;
      });
    });
</script>

html

<div id="stuff">
    <a href="" id="foo-link">Foo</a>
    <a href="" id="bar-link">Bar</a>
    <a href="" id="bob-link">Bob</a>
    <div id="foo-box">Hello</div>
    <div id="bar-box">World</div>
    <div id="bob-box">!!!</div>
</div>

But after clicking on a link I want it to be normal text. I can't seem to figure out a good, elegant way of doing this in javascript (I've found a few ways that may work, but are basically hacks).

Am I just being thick?

6
  • if you mean the coloring of the link - a:visited { text-decoation: none }
    – Bakudan
    Commented Jul 21, 2011 at 12:13
  • you mean you want to remove the link after clicking Commented Jul 21, 2011 at 12:14
  • Yes, it's not clear to what 'normal text' related to Commented Jul 21, 2011 at 12:15
  • typo - you mean text-decoration Commented Jul 21, 2011 at 12:17
  • I'm thinking it might be about functionality of the links rather than the looks of them. It's not like you have to use <a> tags to do this anyways.
    – Joonas
    Commented Jul 21, 2011 at 12:21

3 Answers 3

1

maybe jquery replaceWith() would help?

  $('#bar-link').click(function() {
    ...
     $(this).replaceWith($(this).text());
     return false;
  });
1
  • This literally replaces the link with plain text, as per the OP request. If you just want it to appear as normal text, do a styling tweak a la @DrStrangeLove's suggestion Commented Jul 21, 2011 at 12:20
0
$('#bar-link').click(function() {
        $('#foo-box').hide();
        $('#bob-box').hide();
        $('#bar-box').show();
        $(this).css('text-decoration', 'none');
         return false;
      });
0
$("a").click(function() {
    $(this).addClass("visited");
}

.visited {
    color: black;
    text-decoration: none;
}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.