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.
I also tried doing <div target="_blank">
but it didn’t make any effect, instead it was treated as a normal <div>
.
2
Answers
Add a class to
<div>
elements which must have<a>
elements with blank targets, then use the CSS selector.target_blank a
to locate all<a>
elements that are children of an element with the class. You can loop over them and set the.target
property. Code is shown below:You can simply add a class to the
<div>
elements whose<a>
element must gettarget="_blank"
, then use the CSS selector.target_blank a
to get all<a>
elements that are children of an element with that class. From there you can just loop over them and set the.target
property: