Alternative for innerHTML?

前端 未结 12 810
遇见更好的自我
遇见更好的自我 2020-12-04 13:34

I\'m wondering if there\'s a way to change the text of anything in HTML without using innerHTML.

Reason I\'m asking is because it\'s kinda frowned upon by the W3C. I

12条回答
  •  误落风尘
    2020-12-04 13:47

    It appears to me that the CSS+HTML+JS combination should achieve desired effects:

    .myelement:before {   
        content: attr(alt);
    } 
    
    ...
    
     
    
    ...
    
    element.setAttribute('alt', 'new value'); 
    

    Does anyone know if this works in practice?

提交回复
热议问题