在jquery中将href添加到类中

在jquery中将href添加到类中,jquery,Jquery,我有一门课: <section class="banner booking-widget-home" data-path="/content/xxx/yyy/en/jcr:content/bookingwidget" data-bgset="/content/dam/xxx/aa-website/banner/2018/pppp/2018/04/abc%def%20Fare_Web%20Banner.png" style="background-image: url(&quot;h

我有一门课:

<section class="banner booking-widget-home" data-path="/content/xxx/yyy/en/jcr:content/bookingwidget" data-bgset="/content/dam/xxx/aa-website/banner/2018/pppp/2018/04/abc%def%20Fare_Web%20Banner.png" style="background-image: url(&quot;https://www.abc.in/content/dam/pqr/website/banner/2018/target/2018/04/abc%20Flexi%20Fare_Web%20Banner.png&quot;);">
我想在这个类上添加href,这样当我单击背景图像时,单击会将我带到href中提到的url。 我试过使用: $.banner.booking widget home.attrref,www.landingpae.com

但是背景图像是不可点击的。

因为它不是标签,所以不能点击。不要使用href,而是使用onclick和use location.href:

$function{ $.banner.booking-widget-home.clickfunction{ location.href=https://example.com/; }; };
这可能已经添加了href,但这不是一个标记,所以它不会工作。在这个标记上不使用add href。我也尝试过:jQueryYou可以在单击事件上执行类似的操作:$document.readyfunction{$'.booking widget home'。在“单击”上,函数{window.location='www.landingpae.com';}@AmbikaTewari我刚刚给出了另一个答案。让我知道这是否有效?嗨,Praveen,对,有效。但我想在不同的选项卡中打开重定向的url,而不是在同一选项卡中。正在检查如何添加target=\u blank属性。@AmbikaTewari Just replace location.href=https://example.com/; 有窗户。openhttps://example.com/; 易于理解的