jquery text().replace('','') not working

前端 未结 4 875
情深已故
情深已故 2021-01-16 18:33

Hi I am trying for hours now to remove a text string again after I have appended it.

I have a script that handles an accordion and I have some redundancy in text in

4条回答
  •  温柔的废话
    2021-01-16 18:55

    Change

    $( "#redundant_text_wrapper").text().replace('redundantText',''); 
    

    To:

    $( "#redundant_text_wrapper").text().replace(redundantText,'');
    

    Remove the quotes around the variable. That way it will be seen as a variable and not as a string.

    Or

    $("#redundant_text_wrapper").text($("#redundant_text_wrapper").text().replace(redundantText,''));
    

    This way it will first get the text than replace it and set it.

提交回复
热议问题