Home  >  Q&A  >  body text

javascript - get string in tag


The picture shown is an html string. Is there any way to get the content in the red box?

为情所困为情所困2662 days ago832

reply all(5)I'll reply

  • 滿天的星座

    滿天的星座2017-07-05 10:45:32

    var dom = $('a').clone();
            dom.find('i,button').remove();
            console.log(dom.html());

    reply
    0
  • 天蓬老师

    天蓬老师2017-07-05 10:45:32

    Provide an idea to use regular expressions to match tag segments...

    reply
    0
  • 高洛峰

    高洛峰2017-07-05 10:45:32

    First get the dom of the a tag
    Then find the node whose nodeName is '#text' from the a.childNodes array and get the nodeValue.

    reply
    0
  • 世界只因有你

    世界只因有你2017-07-05 10:45:32

    You can refer to my answer to this question, the idea is the same:
    /q/10...

    Also attached is a method to convert code strings into DOM:
    https://stackoverflow.com/que...

    var code = '<li>text</li>';
    var p = document.createElement('p');
    p.innerHTML = code;
    
    var elements = p.childNodes;

    reply
    0
  • 三叔

    三叔2017-07-05 10:45:32

    If it can be converted into a DOM object, use javascript; if it can only use strings, use regular matching.

    reply
    0
  • Cancelreply