jQuery:拉取链接目标并将其附加到后台类

时间:2015-04-20 01:28:56

标签: jquery class hyperlink background href

我尝试从Squarespace中的文字说明中提取链接并将其附加到我创建的背景类中,以便整个区域可以点击。我尝试过的任何东西都不会起作用。

下面是完整的脚本,它描述了描述(SQSP通常不会这样做),但这是我在许多人中尝试使整个背景区域可点击的事情之一。

 $(window).load(function() {
    $('<div class = "desc-wrapper"></div>').appendTo('.margin-wrapper');
    $('.sqs-gallery-design-grid-slide a[data-description]').each(function(index, el) {
        var $el = $(el),
            desc = $el.data('description');   
        $el.after($('<div class = "image-slide-description">'+desc+'</div>'));

        $('.image-slide-description p').addClass('.desc-wrapper');

        $('.desc-wrapper').click(function() {
            window.location = $(this).find("a").attr("href"); 
            return false;
       });
    });
 });

以下是该平台生成的HTML:

<div class="slide sqs-gallery-design-grid-slide" data-type="image" id="yui_3_17_2_3_1429494555451_956">
       <div class="margin-wrapper" id="yui_3_17_2_3_1429494555451_955">
            <a data-title="Title" data-description="<p><a target=&quot;_blank&quot; href=&quot;http://pitchfork.com&quot;>I am bad at life. But life is bad. But it gets better. There's no win-wn.</a></p>" href="http://static1.squarespace.com/static/5498e617e4b0c49940a535ef/54adbb5ae4b0a1c60d2da9c4/54adbb5ee4b0c9b72f217dc8/1426209403214/_MG_6193.jpg" class="image-slide-anchor content-fill" id="yui_3_17_2_3_1429494555451_954" style="overflow: hidden;">
              <noscript>&lt;img src="http://static1.squarespace.com/static/5498e617e4b0c49940a535ef/54adbb5ae4b0a1c60d2da9c4/54adbb5ee4b0c9b72f217dc8/1426209403214/_MG_6193.jpg"  alt="Title"  /&gt;</noscript><img class="thumb-image loaded" data-src="http://static1.squarespace.com/static/5498e617e4b0c49940a535ef/54adbb5ae4b0a1c60d2da9c4/54adbb5ee4b0c9b72f217dc8/1426209403214/_MG_6193.jpg" data-image="http://static1.squarespace.com/static/5498e617e4b0c49940a535ef/54adbb5ae4b0a1c60d2da9c4/54adbb5ee4b0c9b72f217dc8/1426209403214/_MG_6193.jpg" data-image-dimensions="1391x1800" data-image-focal-point="0.5,0.5" data-load="false" data-image-id="54adbb5ee4b0c9b72f217dc8" data-type="image" alt="Title" src="https://static1.squarespace.com/static/5498e617e4b0c49940a535ef/54adbb5ae4b0a1c60d2da9c4/54adbb5ee4b0c9b72f217dc8/1426209403214/_MG_6193.jpg?format=300w&amp;storage=local" data-image-resolution="300w" style="opacity: 1; top: -35px; left: 0px; width: 238px; height: 308px; position: relative;">
            </a><div class="image-slide-description"><p class=".desc-wrapper"><a target="_blank" href="http://pitchfork.com">I am bad at life. But life is bad. But it gets better. There's no win-wn.</a></p></div>
       <div class="image-slide-title">Title</div>
   <div class="desc-wrapper"></div></div>
</div>

0 个答案:

没有答案
相关问题