访问锚标记的innerHTML

时间:2014-05-06 19:56:24

标签: jquery-selectors selectors-api

我无法访问某些需要用作菜单栏标题的innerHTML: 有关详细信息,请参阅附图...

标题" AMRIS"我需要将javascript变量存储为字符串。

稍后我将使用以下代码填充Bootstrap菜单,其中包含标题I grab:

echo '<script type="text/javascript">

var subTitle = document.getElementById("mobMenuTitle2");

//This is currently filling the Sub Menu with a title// 
subTitle.innerHTML = "Sub Test"; 

</script>';

RIGHT-CLICK&gt;在新标签中打开图像以查看完整尺寸

enter image description here

2 个答案:

答案 0 :(得分:1)

如果你需要打开项目的html,请尝试这样

var openedList = document.getElementsByClassName('opened');
var menuLink = openedList[0].getElementsByClassName('menu-link');
var anchorText = menuLink[0].innerHTML;

相反,如果你想检索列表X的html(X是基于数字0)

var accordion = document.getElementsByClassName('accordion-menu');
var list = accordion[0].getElementsByTagName('li');
var menuLink = list[X].getElementsByClassName('menu-link');
var anchorText = menuLink[0].innerHTML;

答案 1 :(得分:0)

var opn = $(".accordion-menu.opened.menu-link").context.title;

var opnr = opn.replace("MagLab", "");

var subTitle = document.getElementById("mobMenuTitle2")

subTitle.innerHTML = opnr;