简体   繁体   English

设置元素href值jQuery

[英]Setting element href value jQuery

There are a few posts on this already, and this one which couldn't be more simple to follow. 已经有一些关于此的文章,而这一篇文章再简单不过了。 For some reason though I can't get the element to link to the href attribute. 由于某种原因,尽管我无法将元素链接到href属性。

This is the class for the element that needs to be linked: .vc_tta-tab:nth-child(1) ; 这是需要链接的元素的类: .vc_tta-tab:nth-child(1) ;

There is an anchor on the page #about ; #about网页上有一个锚点。

This is the jQuery I'm using: 这是我正在使用的jQuery:

<script>
jQuery('.vc_tta-tab:nth-child(1)').prop('href','https://example.com/#about');
</script>

The idea is to use the .vc_tta-tab:nth-child(1) element to link to the /#about section on the page. 这个想法是使用.vc_tta-tab:nth-child(1)元素链接到页面上的/#about部分。

Please can someone help me correct what I'm doing wrong? 请有人可以帮助我纠正我在做什么错吗?

VDesign is right about using attr instead of prop . VDesign关于使用attr而不是prop是正确的。 For your URL I think you might need the actual page to use the anchor. 对于您的URL,我认为您可能需要使用实际页面才能使用锚点。 Like http://example.com/index.html#about instead of http://example.com/#about . 类似于http://example.com/index.html#about而不是http://example.com/#about

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM