admin管理员组文章数量:1414621
this should be a pretty basic question. I would like to have some html listing:
- A
- B
- C
And by clicking on one of the elements, something should be displayed below. For example, when clicking B, we obtain:
- A
- B
"bla bla bla" - C
I guess there are many ways to achieve that. I just would like the easiest/cleanest way to do that.
Thanks,
Arnaud
this should be a pretty basic question. I would like to have some html listing:
- A
- B
- C
And by clicking on one of the elements, something should be displayed below. For example, when clicking B, we obtain:
- A
- B
"bla bla bla" - C
I guess there are many ways to achieve that. I just would like the easiest/cleanest way to do that.
Thanks,
Arnaud
4 Answers
Reset to default 5<script>
function open_item(sender) {
sender.getElementsByTagName('div')[0].style.display = 'block';
}
</script>
...
<ul>
<li onclick="open_item(this);">
A
<div style="display: none;">bla bla</div>
</li>
<li onclick="open_item(this);">
B
<div style="display: none;">bla bla</div>
</li>
<li onclick="open_item(this);">
C
<div style="display: none;">bla bla</div>
</li>
</ul>
One of many, many, many ways to acplish the same.
I would use jQuery.
Give every element an ID, set a onClick listener via jQuery to every element and let it run a function which looks for a child element (like a <p>
or something you wanna surround your content with) and display it.
Here is a simple jQuery function that uses insertAfter
$('li').click(function() {
$('<span>blah blah</span>').insertAfter(this);
});
See it in action here: http://jsfiddle/WwCcF/
You can add dynamic content with jQuery :
$("li").click(function() {
$(this).append("<br />bla bla bla");
});
I write a pure JavaScript code...
本文标签: htmljavascript clickable textStack Overflow
版权声明:本文标题:html - javascript clickable text - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745162060a2645481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论