how to assign a css class to title of svg element using javascript?

后端 未结 2 1570
傲寒
傲寒 2021-01-28 12:10

I have used this: That does not work. I have added both of urs suggestion.. but it did not work!

svg
{
 width:720px;
 height:50px;
 border:#999999 solid 2px;
}
.         


        
2条回答
  •  礼貌的吻别
    2021-01-28 12:47

    You can add it as below:

    title.classList.add("tooltip");
    

    Here is the DEMO

    UPDATE:

    Check this Updated Demo

    There were some console errors which I have cleared.

    Just copy and paste the javascript part as it is in your page and see that class will be added now. One major change was that you were adding class to title along with . like title.classList.add('.tooltip'); but it should have been without . like title.classList.add('tooltip'); Check the demo and let me know!!

提交回复
热议问题