English 中文(简体)
如何在<div>上将所有内容设定到空白目标(目标=“空白”)
原标题:How to set all content in a <div> to a blank target (target="_blank")

I need to set all of the content in a certain <div> to open to another tab ( target="_blank"). I don t really care how this is solved, you can use JS, CSS, HTML, classes, IDs, et cetera.

I tried using <base target="_blank"> but it covered everything no matter what rather than just a certain area. Example: <a href="example.html"> <div> <base target="_blank"> [CONTENT] </div> I thought that example.html would be opened in the same tab, but its target is set to "_blank" as well.

我也尝试做以下工作:<div Target="_blank”>,但该编号没有产生任何效果,而是作为正常的<代码><div>处理。

问题回答

您可以简单地在<代码>和>、div> 内容<a> 内容必须达到target='_blank”,然后使用CSS的甄选器<代码>.target_blank a,以获取所有<a>元素,这些元素是该类元素的儿童。 从那里看,你可以自行处理这些财产,并设定<编码>。

const target_blank = document.querySelectorAll( .target_blank a );
for (const el of target_blank) {
  el.target = "_blank";
}
<div class="target_blank">
  <a href="https://example.com" id="test1">Test 1</a>
  <div>
    <a href="https://example.com">Test 2</a>
  </div>
</div>

<a href="https://example.com" id="test3">Test 3</a>
<a href="https://example.com">Test 4</a>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签