Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Selector Question -- How to find all HREF's with a target = _blank?

My "JQuery Selector Foo" stinks. I need to find all HREF's with a target attr of _blank and replace them with a common window/target. Assistance is greatly appreciated!

like image 487
Jason S. Burton Avatar asked Sep 21 '11 21:09

Jason S. Burton


People also ask

How to select element by id using jQuery?

In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.

How jQuery selector works?

jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.

What is target _blank in Javascript?

Description. _blank. Opens the linked document in a new window or tab. _self. Opens the linked document in the same frame as it was clicked (this is default)

How do you add a target blank to a URL?

Conclusion. You can use the target="_blank" attribute if you want your users to click on a link that opens up a new browser tab. The target="_blank" attribute is used inside the opening anchor tag like this.


2 Answers

try

        $("a[target=_blank]").each(function () {
            var href = $(this).attr("href"); // retrive href foreach a
            $(this).attr("href", "something_you_want"); // replace href attribute with wich u want
            // etc
        });

let me know what do you want, for more help

like image 181
amiry jd Avatar answered Oct 09 '22 10:10

amiry jd


$("a[target='_blank']").attr('target', 'sometarget');

Do you mean something like that?

like image 27
Ry- Avatar answered Oct 09 '22 11:10

Ry-