开发者

Jquery: Select full href with a 'contains' method

Is it possible using jQuery to select one full link which href contains another variable?

My code is:

var element1 = $(".not-viewed").parents('li').attr("id");

var element2 = $(".videoTitle").attr("href");

Where i need to select a full link that contains 'element1',because there several videos in the page.In my code select the first on the page,but i need the specific with id.. Example..[In this example the code that i need is: 1581889025]

    <li class="videoContainer vidLink" id="1581889025">
    <a href="site.com../view/1581889025:49_3eA8F7sPr5FQGZcl2yzx3dz5Y_XwP">
    <span class="HOVER"></span>
    <div class="videoX"><img id="clThumb_1581889025" src="PREVIEW.jpg">
    </开发者_如何学运维div>  </a>
    <a class="videoTitle" href="site.com../view/1581889025:49_3eA8F7sPr5FQGZcl2yzx3dz5Y_XwP">Title of Video</a>
<span class='not-viewed'></span>
<div class="tooltip-footer"></div>
</li>

Thanks in advance. Kind regards.


You can use the attribute-contains selector (*=), like this:

var id = $(".not-viewed").parents('li').attr("id");
var href = $(".videoTitle[href*='" + id + "']").attr("href");

You can give it a try here, you may also want $(".videoTitle[href*='/" + id + ":']") to narrow it down to /1581889025: matches, in case there was a 15818890250 for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜