How to make a link in a new window, the window to apply to the entire class in jquery?

Good time of day.
Tell me how to do a link in a new window, that apply to the entire class in jquery
I have written so
var target='.free_domain';
$(target).each(function(){
$(this).click(function(){
 location = $(this).find('a').attr('href');});
$(this).css('cursor','pointer');
 $(".free_domain [href^='http://google.com']").attr("target","_blank");
 });

now the mouse defines a class as a link, but does not go to a new window google.com
Please help!
Very urgent need.
June 26th 19 at 14:06
1 answer
June 26th 19 at 14:08
$(this).click(function(){
 location = $(this).find('a').attr('href');
});
$(this).css('cursor','pointer');

It's too much.
- - - - - - - - - - - -
To replace it:
$(".free_domain [href^='http://google.com']").attr("target","_blank");

This:
$(".free_domain a[href*='google.com']").attr("target", "_blank");

UPD#1: but your example is also working
https://jsfiddle.net/yarkov_aleksei/rdouvykc/
Thanks for the reply.
I don't want to write the link (url)
as html code, no link, only a link in jquery
wrote so, does not work.

$(".free_domain a[href*='google.com']").attr("target", "_blank");
- amani_Casp commented on June 26th 19 at 14:11
:
wrote so, does not work.

I mean? Open the example on the link, I changed to your code. All already running running.
as html code, no link, only a link in jquery

What??? - idella_Stoltenberg2 commented on June 26th 19 at 14:14
link to entire class does not apply. - amani_Casp commented on June 26th 19 at 14:17
: I ceased to understand you. You example looked? What's wrong? The markup is not available? Well, I'm sorry. My inner psychic is not capable of more. Show your example and explain what is wrong and how it should be. - idella_Stoltenberg2 commented on June 26th 19 at 14:20
var states = [
 ['Busy !', 'busy'], // busy
 ['Free !<br><a class="domen_bay" ">Buy now!</a>', 'free_domain'], // free
];

 function ajax() {
$.ajax({
 type: 'POST',
 url: '../library/checkdomain.php',
 data: { sld: sld, tld: tld[index] },
 dataType: 'json',
 beforeSend: function(){
},
 success: function(data){
 switch (data.status) {
 case '0':
 state = 0; // busy
break;
 case '1':
 state = 1; // free
break;
 case '2':
 state = 2; // incorrect format
break;
 case '3':
 state = 3; // request error
break;
default:
 state = 4; // server error
}
},
 error: function(){
 state = 5; // network error
},
 complete: function() {
console.log(states[state][0]);
 $('div[data-id="'+tld[index]+'"]').html('<p class="requestext">Result !</p><div class="'+states[state][1]+'">'+states[state][0]+'</div>');

 if (tld[++index]) {
ajax();
 } else {
 $check.prop('disabled', false);
$('button[name=clear_res]').show();
}
}

});
$(".free_domain a[href*='panel.webvm.ru/OFFERTA/offerta_add_select_type.khtml']").attr("target", "_blank");
}
});

well here is the incomplete code. - amani_Casp commented on June 26th 19 at 14:23
: and what's wrong? The problem here is?
$(".free_domain a[href*='panel.webvm.ru/OFFERTA/offerta_add_select_type.khtml']").attr("target", "_blank");
- idella_Stoltenberg2 commented on June 26th 19 at 14:26
link only works on the buy button, not the whole class .free_domain - amani_Casp commented on June 26th 19 at 14:29
: Well, I don't see a problem. Let's link. Will look at the place. - idella_Stoltenberg2 commented on June 26th 19 at 14:32
here - amani_Casp commented on June 26th 19 at 14:35
: 76f91475d73f457b9c93c8c63b09df2c.png
Well what do you want? At the link there is no href attribute. - idella_Stoltenberg2 commented on June 26th 19 at 14:38
how to write default href="#" ? - amani_Casp commented on June 26th 19 at 14:41
In href you need to write the address in a new window will open. - idella_Stoltenberg2 commented on June 26th 19 at 14:44
wrote, but why the yellow background is not done as a link? - amani_Casp commented on June 26th 19 at 14:47
: and what for? Now everything works fine. Link opens in a new window as I wanted. - idella_Stoltenberg2 commented on June 26th 19 at 14:50
need.
How to make the whole block a link?
<div class="free_domain">

</div>
- amani_Casp commented on June 26th 19 at 14:53
:
$('.free_domain').click(function(){
 const a = $(this).find('a[href^="panel.webvm.ru/OFFERTA"]');
 a.attr('target', '_blank');
a.trigger('click');
});
- idella_Stoltenberg2 commented on June 26th 19 at 14:56
not working. the link changed didn't help.
as I understand you, your code needs to be replaced?
$(".free_domain a[href*='panel.webvm.ru/OFFERTA/offerta_add_select_type.khtml']").attr("target", "_blank");
- amani_Casp commented on June 26th 19 at 14:59
: https://jsfiddle.net/yarkov_aleksei/n7Ld3nx2/ - idella_Stoltenberg2 commented on June 26th 19 at 15:02
why the red background is not a link? - amani_Casp commented on June 26th 19 at 15:05
: YOU BLEW MY MIND!!! So as not to link??? Have you tried on background click?????? - idella_Stoltenberg2 commented on June 26th 19 at 15:08
Excuse me please!!! For God's sake forgive me. - amani_Casp commented on June 26th 19 at 15:11
The pancake )))) Well, just be a little careful and all. Your question solved? - idella_Stoltenberg2 commented on June 26th 19 at 15:14
Thank you all. Happy holidays to you! - amani_Casp commented on June 26th 19 at 15:17
: mutually! - idella_Stoltenberg2 commented on June 26th 19 at 15:20
:D - Trevion.Balistreri commented on June 26th 19 at 15:23

Find more questions by tags jQuery