[英]Change image source through javascript does not seem to work. What am I doing wrong?
I'm trying to change the current logo of this website: https://moonstrategy.io/about/ from我正在尝试更改此网站的当前徽标: https://moonstrategy.io/about/ from
https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_light_final.svg to https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_final.svg https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_light_final.svg to https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_final.svg
I'm embedding this code in the webpage:我将此代码嵌入网页中:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>document.getElementByClassName(".tgp-exclude small").src="https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_final.svg";</script>
I've also tried using different class names and while I'm pretty sure I tried all of them, I can either not seem to find the right one, or I am totally off with the code.我也尝试过使用不同的 class 名称,虽然我很确定我尝试了所有这些名称,但我似乎找不到合适的名称,或者我完全不使用代码。
Help would be appreciated.帮助将不胜感激。
getElementByClassName
, there is getElementsByClassName
getElementByClassName
这样的东西,有getElementsByClassName
getElementsByClassName
returns NodeList and you want only one element, use querySelector
instead. getElementsByClassName
返回 NodeList 并且您只需要一个元素,请改用querySelector
。 nothing wrong here but I think the document.getElementsByClassName() returns an array of elements with the specified class name So it should be something like这里没有错,但我认为 document.getElementsByClassName() 返回具有指定 class 名称的元素数组所以它应该类似于
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.