SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Trouble with .before jQuery

    I have a very simpel jQuery function where i want to pass the link string containg an url to a span containing a class called .post-link

    But the whole string of link is not being passed before .post-link.
    Can anybody please tell me why. According to jQuery library i should be able to pass html with .before()

    The link is being copyed from a span
    HTML Code:
    <span class="post-link">some link</span>
    Code:
    $('.postContainer').each(function(i) {
    	var link = '<a href="' + $(this).find('.post-link').text() + '">';
    	  $(this).find('.headline').before(link);
    	  $(this).find('.post-link').before('</a>');
    });

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    It's the context of what it's being placed before which is causing the trouble.
    '</a>' is not a valid reference to an element in the DOM, so nothing can be placed before it.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

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
  •