SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery .after usage

    I'm just trying to replace a link with some text, so I'm trying to use .after(), and then hide(). The link is hidden, but the replacement text does not appear.

    Code:
    var the_link = $(this);
    $(the_link).after('Replacement Text');
    $(the_link).hide();
    What's wrong here? The examples I see online make this seem like it should work.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The below sample works fine for me.

    Code JavaScript:
    <a id="the_link" href="">Test Link</a>
     
    <script>
    	$(document).ready(function() {
    		$('#the_link').after('Replacement Text');
    		$('#the_link').hide();
    	});		
    </script>

    I suspect something else may be effecting your code. Can you show the rest of the code?

  3. #3
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suspect that since I was dealing with a link that was not always the same link, and I had to use "this", that somehow the usage was affected. Since I am bound by contract not to show the code, I can't post the actual code, but I fixed my problem by chaining hide on to the end of after:

    Code:
    $(the_link).after('Replacement Text').hide();
    It's things like this that make me stumble. Why the above code works but the original code doesn't is beyond my knowledge of javascript and jquery.


Bookmarks

Posting Permissions

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