[英]Get Text Inside Anchor tag
i want to get text inside anchor text and show in p tag 我想在锚文本中获取文本并显示在p标签中
example :- 例如:
<p class="post">
some content
<span more-description="here is read more description">...</span>
<a class="readmore">Read More</a>
</p>
so after click on "Read More" text. 因此,请点击“阅读更多”文字。
the new source code will be:- 新的源代码将是:
<p class="post">
some content
<span class="full">here is read more description</spn>
<span more-description="here is read more description" style="display:none;">...</span>
<a class="readmore">Read More</a>
</p>
$(document).ready(function(){
$('.readmore').click(function(){
var span=$('<span>');
span.addClass('full').text($('[more-description]').attr('more-description'));
$('p').prepend(span);
$('[more-description]').hide()
})
})
In plain Javascript: 用简单的Javascript:
document.querySelector(".readmore").onclick = function () {
var span = document.createElement('span');
span.className = 'full';
span.innerHTML = 'here is read more description';
var post = document.querySelector('post');
post.insertBefore(span, post.childNodes[0]);
post.childNodes[1].style.display = 'none';
}
simple way to do it without other frameworks: 没有其他框架的简单方法:
<p class="post">
some content
<span class="full" style="display:none">here is read more description</span>
<span more-description="here is read more description" style="display:none;">... </span>
<a class="readmore" onclick="document.getElementsByClassName('full')[0].style.display='block';" >Read More</a>
</p>
or display='inline-block' 或display ='inline-block'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.