[英]Taking a dynamic elements attribute and using it in another element
Hi I have a dynamically created button created by a plugin I am using on my page. 嗨,我有一个动态创建的按钮,该按钮由我在页面上使用的插件创建。 Basically, the element created by the javascript is a breadcrumb with a 'href'.
基本上,由javascript创建的元素是带有“ href”的面包屑。 I was hoping to take the same link and apply it to another button.
我希望采用相同的链接并将其应用于另一个按钮。 However my theory is not working, how would you do this?
但是我的理论不起作用,您将如何做?
/* M Y C O D E */
var link5 = $('#sideButton5').attr('href');
$("#menu5").attr("href", ""+link5+"");
console.log(link5);
/* P L U G I N */
for (var i = 0; i < $(SECTION_SEL).length; i++) {
var link = '';
if (options.anchors.length) {
link = options.anchors[i];
}
li += '<li><a id="sideButton'+i+'" href="#' + link + '"><span class="fp-sr-only"></span><span></span></a>';
// Only add tooltip if needed (defined by user)
var tooltip = options.navigationTooltips[i];
if (typeof tooltip !== 'undefined' && tooltip !== '') {
li += '<div class="' + SECTION_NAV_TOOLTIP + ' fp-' + options.navigationPosition + '">' + tooltip + '</div>';
}
li += '</li>';
}
I don't see any problems here. 我在这里看不到任何问题。 You are using jQuery to manipulate DOM, so you should not care about plugins or whatever else.
您正在使用jQuery来操作DOM,因此您不必关心插件或其他任何东西。
<a id="linkA" href="xxx"></a>
<a id="linkB"></a>
var a = $('#linkA').attr("href");
var b = $('#linkB').attr('href', a);
console.log(b);
This sample will work 此示例将工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.