Search code examples
jquerycsspseudo-elementcss-content

Add a link href with css content


I need to set an url after the class module-content, with pure css. This code doesn't work, but basically i need to set the Custom‌·Link in the content: ' ' attr(href);.

<div class="module-content">
   <div class="aidanews2" style="clear: both;">
      <div class="aidanews2_art aidacat_2 aidapage105 hidepiece odd first" style="clear: both; display: block;">
      <div class="aidanews2_art aidacat_2 aidapage105 hidepiece even last" style="clear: both; display: block;">
   </div>
   <div class="aidanews2_bottomlink">
      <a href="/joomla/index.php">Custom‌·Link</a>
   </div>
</div>

.moduletable>.module-content:after{
    background: none repeat scroll 0 0 #050505;
    content: ' ' attr(href);
}

unsuccessful Jquery attempt:

var a = $('.aidanews2_bottomlink').html();
var b = $('.top-1 > .moduletable > .module-content:after ').html(a);

Solution

  • This is perhaps more easily done using JavaScript/jQuery. That would be how I'd approach it, anyways.

    If I understand your requirements correctly, you want to 1) fetch the href attribute on the link and 2) output it as text after the closing tag on the enclosing module-content div.

    That can be accomplished with the following code:

    //get the text
    var content = $(".aidanews2_bottomlink a").attr('href');  
    
    //append it after the containing element
    $(".aidanews2_bottomlink").parents(".module-content").eq(0).after(content);  
    

    Here's a live example: http://jsfiddle.net/ANZgE/2/