开发者

Would this be the best way to do this?

开发者 https://www.devze.com 2023-03-01 18:43 出处:网络
I\'m trying to learn JavaScript by writing a Google Chrome extension for Reddit so I wrote something to display both link and comment karma in the little tab up top.

I'm trying to learn JavaScript by writing a Google Chrome extension for Reddit so I wrote something to display both link and comment karma in the little tab up top.

a = document.getElementById("header-bottom-right");
a.firstChild.firstChild.nextElementSibling.innerText =开发者_开发技巧 "100000"

Obviously it is not the full thing (just finding the correct nodes to edit), but is their a better way to grab the karma text?


Reddit uses jQuery library (an ancient version, but still). So instead of using plain js you could use: $('#header-bottom-right child_tag').html('10000') (you can also use custom html there)

With plain js could be something like this:

var hbr = document.getElementById('header-bottom-right');
var links = hbr.getElementsByTagName('a'); // replace this with what tag you want to change
links[0].innerHTML = 'your cool text';


May not be the best way, but you may be able to use innerHTML instead.

document.getElementById('header-bottom-right').firstChild.firstChild.nextElementSibling.innerHTML
0

精彩评论

暂无评论...
验证码 换一张
取 消