how I can select the <a>
tag containing the href="www.dummy.ch"
in the following code with jquery
.
I have to modify the target attribute with _top
instead of _blank
.
No ID or class attribute is set in the tag.
Thanks, Patric
<div class="QvContent" style="width: 485px; height: 26px; overflow: visible; border-bottom-right-radius: 1px; border-bottom-left-radius: 1px; background-color: rgba(255, 255, 255, 1);">
<div class="QvGrid" style="width: 485px; height: 26px; overflow: hidden; font-family: Tahoma; font-size: 8pt; font-style: normal; font-weight: normal; text-decoration: none; position: relative; cursor: default;" incontainer="false" fixed_cols_left="1">
<a style="position: absolute;" href="http://www.dummy.ch" target="_blank" unselectable="on">
<div title="URL " style="left: 0px; top: 0px; width: 389px; height: 13px; text-align: center; color: rgb(54, 54, 54); overflow: hidden; font-style: normal; font-weight: normal; text-decoration: underline; position: absolute; cursor: pointer; background-color: rgba(255, 255, 255, 1);">
<div style="left: 0px; top: 0px; width: 389px; height: 13px; border-left-color: rgba(220, 220, 220, 1); border-left-width: 0px; border-left-style: solid; position: absolute;" unselectable="on"/>
<div class=" injected" style="padding: 0px 2px; width: 385px; height: 13px;">
<div title="URL " style="width: 385px; overflow: hidden; white-space: pre; cursor: default; -ms-word-wrap: normal;" unselectable="on">
<a style="display: inline-block;" href="http://www.axeed.ch" target="_blank" unselectable="on">URL</a>
</div>
</div>
</div>
</a>
</div>
</div>
答案 0 :(得分:1)
试
$("a[href*='www.dummy.ch']").attr("target", "_top");
答案 1 :(得分:1)
试试这个:您可以使用jquery的 attribute containing selector 来获取包含www.dummy.ch的href值的所有锚点并更改其目标值。
$("a[href*='www.dummy.ch']").attr("target", "_top");
答案 2 :(得分:0)
如果您想要域名和子域名:
$("a[href*='dummy.ch']").attr("target", "_top");
如果您想要没有子域名的域名:
$("a[href*='//dummy.ch']").attr("target", "_top");
如果您想定位特定协议:
用任何你想要的东西$("a[href^='http://dummy.ch']").attr("target", "_top");
(替换&#34; http&#34;)。
* = 部分表明href属性包含 dummy.ch 。 ^ = 部分意味着href标记以引号内的内容开头。