[英]change anchor tag inner html by title using javascript
i have an anchor tag as follows: 我有一个锚标记,如下所示:
<a title=“mytagname”>My name is akira</a>
I want to write a javascript so that I can search the a tag with the title value and change the inner html of that. 我想编写一个JavaScript,以便我可以搜索带有标题值的标记并更改其内部html。
function changeContentByTagName(tagName, newContent) {
var elem = document.querySelector('a[title='+ tagName +']');
if (elem) {
elem.innerHTML = newContent;
}
}
usage: changeContentByTagName('mytagname', 'My name is Tetsuo');
用法: changeContentByTagName('mytagname', 'My name is Tetsuo');
Or if you are using jQuery 或者,如果您使用的是jQuery
function serchAndChange (title, content){
var selector = '[title='+title+']';
var $element = $(selector);
if($element){
$element.html(content);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.