相关疑难解决方法(0)

JavaScript中的querySelector和querySelectorAll vs getElementsByClassName和getElementById

我想知道究竟是什么之间的差异querySelectorquerySelectorAll对抗 getElementsByClassNamegetElementById

这个链接我可以收集,querySelector我可以编写document.querySelector(".myclass")获取类的元素,myclassdocument.querySelector("#myid")获取ID元素myid.但我已经可以做到这一点getElementsByClassNamegetElementById.应该首选哪一个?

我也在XPage中工作,其中ID是用冒号动态生成的,看起来像这样view:_id1:inputText1.所以当我写document.querySelector("#view:_id1:inputText1")它不起作用.但写作document.getElementById("view:_id1:inputText1")有效.有什么想法吗?

javascript

148
推荐指数
8
解决办法
10万
查看次数

从javascript更改伪元素样式

如何更改CSS的伪元素样式?


我正在尝试获取CSS before::规则并将其更改left:95%4px。如何在我的上下文中执行此操作?

我也使用进行了一些测试,document.querySelector但是它不起作用,出现了计算只读错误。

有什么建议吗?


例:

的CSS

.iziToast-wrapper-bottomLeft .iziToast.iziToast-balloon:before {
  border-right: 15px solid transparent;
  border-left: 0 solid transparent;
  right: auto;
  left: 8px;
}
Run Code Online (Sandbox Code Playgroud)

js

    if(description_iziToast){
        let RightMode = event.x>window.innerWidth/2;
        let bubblePosition = document.getElementsByClassName("iziToast-balloon")[0]; // get the div that hold the bubble
        let ajustScreenLR = RightMode && document.getElementsByClassName("iziToast")[0].offsetWidth || 0; // halfScreen ajustement
        //bubblePosition.style.left = RightMode && '95%' || '4px'; // here i need to change the position in the befor:: attribut …
Run Code Online (Sandbox Code Playgroud)

javascript css dom pseudo-element

2
推荐指数
2
解决办法
3349
查看次数

标签 统计

javascript ×2

css ×1

dom ×1

pseudo-element ×1