HTML悬停时突出显示标签

Trying2LearnMath

给定以下内容html

This is a test to
<cpos data-idcpos="10" data-comment="1"> 
  highlight only this portion of text 
</cpos> and not this

我的任务是仅突出显示该cpos部分。我可以自己突出显示div课程,但是对如何执行此操作有些困惑。我正在使用javascript一种css风格

任何帮助,将不胜感激。谢谢!

AmmarCSE

无需javascript,只需使用css :hover

cpos:hover{
  background:yellow;
  }
This is a test to<cpos data-idcpos="10" data-comment="1"> highlight only this portion of text </cpos> and not this

更新

如果我有多个cpos具有不同ID的标签,并且想在悬停时突出显示单个标签

只需将每个ID定位为 #

#MyId:hover{
  background:yellow;
  }
This is a test to<cpos data-idcpos="10" data-comment="1"> highlight only this portion of text </cpos> and not this

This is a test to<cpos id="MyId" data-idcpos="10" data-comment="1"> highlight only this portion of text </cpos> and not this

此外,无论如何,您可以向我展示如何使用javascirpt做到这一点吗?

使用onmouseoveronmouseout事件

This is a test to<cpos data-idcpos="10" data-comment="1" onmouseover="this.style.background='yellow'" onmouseout="this.style.background=''"> highlight only this portion of text </cpos> and not this

有没有一种方法可以类似于您的JavaScript示例,但无需更改cpos标记属性?

是的,遍历它们并以编程方式进行附加

var elements = document.getElementsByTagName('cpos');
for(var i = 0; i < elements.length; i++){
  elements[i].onmouseover = function(){
    this.style.background = 'yellow';
    }
  elements[i].onmouseout = function(){
    this.style.background = '';
    }
  }
This is a test to
<cpos data-idcpos="10" data-comment="1">
  highlight only this portion of text
</cpos>and not this This is a test to
<cpos data-idcpos="10" data-comment="1">
  highlight only this portion of text
</cpos>and not this This is a test to
<cpos data-idcpos="10" data-comment="1">
  highlight only this portion of text
</cpos>and not this

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

d3js悬停在标签上时突出显示森伯斯特路径

来自分类Dev

H2和IMG在A标签中-悬停时都突出显示

来自分类Dev

鼠标悬停时单词突出显示

来自分类Dev

突出显示悬停时的引导程序行

来自分类Dev

在悬停时逐行突出显示段落

来自分类Dev

突出显示悬停时的引导程序行

来自分类Dev

在html表中的鼠标悬停时突出显示选中的行和列

来自分类Dev

在悬停时如何突出显示元素内的文本,而不是整个元素及其填充?CSS / HTML

来自分类Dev

在html表中的鼠标悬停时突出显示选中的行和列

来自分类Dev

忽略HTML标签以突出显示匹配的单词

来自分类Dev

突出显示悬停元素

来自分类Dev

突出显示悬停元素

来自分类Dev

OpenLayers 3:在悬停时显示矢量标签

来自分类Dev

JSPlumb在悬停时显示连接标签

来自分类Dev

悬停在标签上时显示信息

来自分类Dev

OpenLayers 3:在悬停时显示矢量标签

来自分类Dev

Chart js scatter - 在悬停时显示标签

来自分类Dev

leafletjs:鼠标悬停时突出显示折线

来自分类Dev

导航中的元素在悬停时未突出显示整个<li>

来自分类Dev

使用CSS突出显示悬停时的其他元素

来自分类Dev

悬停在突出显示的单词上时播放视频

来自分类Dev

如何添加svg图像,使其在悬停时突出显示

来自分类Dev

突出显示悬停时的所有数字

来自分类Dev

突出显示悬停时指针左移和列向上

来自分类Dev

悬停子项目时突出显示父项目

来自分类Dev

仅在悬停时突出显示单元格

来自分类Dev

Python-悬停时Tkinter单选按钮突出显示

来自分类Dev

使用 css 悬停时突出显示表格行

来自分类Dev

Javascript:div内的元素:悬停时突出显示高度

Related 相关文章

热门标签

归档