Regular expression to get a class name from html

前端 未结 5 1086
温柔的废话
温柔的废话 2021-01-13 09:39

I know my question might look like a duplication for this question, but its not
I am trying to match a class name inside html text that comes from the

5条回答
  •  走了就别回头了
    2021-01-13 10:28

    Use the browser to your advantage:

    var str = '
    \ \
    \ '; var wrapper = document.createElement('div'); wrapper.innerHTML = str; var elements = wrapper.getElementsByClassName('b'); if (elements.length) { // there are elements with class b }

    Demo

    Btw, getElementsByClassName() is not very well supported in IE until version 9; check this answer for an alternative.

提交回复
热议问题