I have some content in HTML format and i want to remove Comments Example between the tags.
For eg: Content is like
<p dir="ltr" id="_13" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: times new roman,times; ">Time span values shall allow creation or retrieval using any of the following units:<br><br> Days<br><br> Hours<br><br> Minutes<br><br> Seconds<br><br> Milliseconds<br><br> Microseconds</span><br><br><span style="font-size: 12pt; font-family: times new roman,times; "><b><i>Comments</i></b></span><span style="font-size: 12pt; font-family: times new roman,times; "><i> Example</i></span></p>
I want to specifically remove Comments Example. I can fetch it in two separate variables, but basically where they are present consecutively there only it should be removed.
Expected result will be:
<p dir="ltr" id="_13" style="margin-left: 0px; "><span style="font-size: 11pt; font-family: times new roman,times; ">Time span values shall allow creation or retrieval using any of the following units:<br><br> Days<br><br> Hours<br><br> Minutes<br><br> Seconds<br><br> Milliseconds<br><br> Microseconds</span><br><br><span style="font-size: 12pt; font-family: times new roman,times; "><b><i></i></b></span><span style="font-size: 12pt; font-family: times new roman,times; "><i></i></span></p>
Thanks in advance!!
You can select the element using span:eq()
, and then just use text()
:
$('#_13').find('span:eq(1) i').text(''); $('#_13').find('span:eq(2) i').text('');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <p dir="ltr" id="_13"> <span style="font-size: 11pt; font-family: times new roman,times;"> Time span values shall allow creation or retrieval using any of the following units:<br><br> Days<br><br> Hours<br><br> Minutes<br><br> Seconds<br><br> Milliseconds<br><br> Microseconds </span><br><br> <span style="font-size: 12pt; font-family: times new roman,times;"><b><i>Comments</i></b></span> <span style="font-size: 12pt; font-family: times new roman,times; "><i>Example</i></span> </p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.