jquery - 如何使用 JQuery 删除具有特定单词 id 或类的 div 并保留内部内容

标签 jquery

我在我的页面中遵循了 HTML

<div class="bi-tearm-rightdesc">
                <div class="bi-tearm-scrollbox customscrollbar mCustomScrollbar _mCS_1"><div id="mCSB_1" class="mCustomScrollBox mCS-light mCSB_vertical mCSB_inside" style="max-height: none;" tabindex="0"><div id="mCSB_1_container" class="mCSB_container" style="position: relative; top: -359px; left: 0px;" dir="ltr">
                    <p>
                        <span class="bold-font">Investment Decisions</span>. The Investor Information web pages are not intended to replace any information or consultation 
provided by a professional financial advisor. Other than the specific information presented in the Investor Information web pages, no information on 
our website is intended to be the basis of or should be relied upon in making an investment decision. Because the North Texas Tollway’s securities 
may involve different sources of payment and security, you should refer to the official statement for any particular security for additional 
information. Materials and information on the North Texas Tollway Authority's website are provided as a public service and intended to provide 
information on matters of public interest. Accordingly, the information in this site is not intended to serve as legal or financial advice.
                    </p>
                    <br>
                    <p><span class="bold-font">Not an Offer to Sell/Buy Securities</span>. The information provided in this website does not constitute an offer to sell 
or buy securities or the solicitation of an offer to sell or buy securities and should not be relied upon to provide specific offering information in 
connection with any issuance, sale, resale, or remarketing of bonds, commercial paper, notes, or other securities.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Dates of Documents; Estimates and Opinions</span>.All documents contained in the Investor Information section of this website 
are marked with a date and speak only as of that date, which may be prior to the date it is posted on this website. No inference should be made that 
the operations of the North Texas Tollway Authority or related entities and/or other economic conditions have remained the same since the date 
indicated. The Investor Information section of this website contains, in part, estimates and matters of opinion which are not intended as statements 
of fact, and no representation is made as to the correctness of such estimates and opinions, or that they will be realized. Any information and 
expressions of opinion herein contained are subject to change without notice.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Information is Subject to Change Without Notice and May Not Be Updated</span>. The North Texas Tollway Authority is under no 
obligation to update any information included in this website and the North Texas Tollway Authority expressly disclaims any duty to provide an update 
of any document contained in this website. The information and expressions of opinion herein are subject to change without notice and the posting of 
information on this website does not imply that there has been no change in the affairs of the North Texas Tollway Authority.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Unavailability of Website</span>.The NTTA makes every effort to keep the website up an in good running condition. However, 
NTTA takes no responsibility for, and is not liable for, the website being temporarily unavailable due to technical issues beyond its control.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Forward-Looking Statements</span>.The documents contained in the Investor Information web pages may contain "forward-looking 
statements" within the meaning of Section 21E of the Securities Exchange Act of 1934, as amended. Such statements may involve known and unknown 
risks, uncertainties, and other factors which may cause the actual results, performance, and achievements to be different from future results, 
performance, and achievements expressed or implied by such forward-looking statements. Investors are cautioned that the actual results could differ 
materially from those set forth in the forward-looking statements.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Interim Financial Information</span>.All interim financial information provided on the Investor Information web pages is 
preliminary and unaudited and subject to adjustment.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Links to Other Websites</span>.The North Texas Tollway Authority may provide links to other websites to allow investors 
independent access to other organizations whose expertise may be of value. The inclusion of any links does not imply a recommendation or endorsement 
of the views expressed within them. The North Texas Tollway Authority has not participated in the preparation, compilation, or selection of 
information on any other website, and assumes no responsibility or liability for the views, content, or accuracy of any other website referenced or 
linked through the North Texas Tollway Authority's website.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Other Information May Be Available</span>. The Investor Information section of this website is provided for the convenience 
of investors in North Texas Tollway Authority, but it does not provide a full and complete set of information that is of interest to investors. There 
may be other documents containing relevant information regarding the North Texas Tollway Authority, which may be available from other sources, 
including by request from the North Texas Tollway Authority.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Disclaimers</span>. THE NORTH TEXAS TOLLWAY AUTHORITY SHALL NOT BE HELD LIABLE FOR ANY IMPROPER OR INCORRECT USE OF THE 
MATERIALS OR INFORMATION CONTAINED ON THIS SITE AND ASSUMES NO RESPONSIBILITY FOR ANY USER'S USE OF THEM. IN NO EVENT SHALL THE NORTH TEXAS TOLLWAY 
AUTHORITY BE LIABLE, WITHOUT LIMITATION, FOR ANY DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SITE OR THE MATERIALS AND INFORMATION CONTAINED ON 
THIS SITE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE, WHETHER INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL. THIS DISCLAIMER OF 
LIABILITY APPLIES TO ANY DAMAGES OR INJURY WHETHER FOR BREACH OF CONTRACT, TORTIOUS BEHAVIOR, NEGLIGENCE, OR UNDER ANY OTHER CAUSE OF ACTION.
                    </p>
                    <p><br>THE MATERIALS IN THIS SITE ARE PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND EXPRESS OR IMPLIED. TO THE FULLEST EXTENT PERMISSIBLE, THE 
NORTH TEXAS TOLLWAY AUTHORITY DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED. THE NORTH TEXAS TOLLWAY AUTHORITY DOES NOT WARRANT OR MAKE ANY 
REPRESENTATIONS REGARDING THE USE OR THE RESULTS OF THE USE OF THE MATERIALS IN THIS SITE, OR THROUGH LINKS TO OTHER SITES, IN TERMS OF THEIR 
CORRECTNESS, ACCURACY, RELIABILITY, COMPLETENESS OR OTHERWISE.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Indemnification</span>. To the extent permitted by applicable law, by using the North Texas Tollway Authority's website, the 
user agrees to defend, indemnify, and hold harmless, the North Texas Tollway Authority, its agencies, officers, employees, representatives, and 
agents from and against all claims and expenses, including attorneys' fees, arising out of the user's use of this site or materials and information 
contained on this site.
                    </p>
                </div><div id="mCSB_1_scrollbar_vertical" class="mCSB_scrollTools mCSB_1_scrollbar mCS-light mCSB_scrollTools_vertical mCSB_scrollTools_onDrag" style="display: block;"><div class="mCSB_draggerContainer"><div id="mCSB_1_dragger_vertical" class="mCSB_dragger mCSB_dragger_onDrag" style="position: absolute; min-height: 30px; display: block; height: 40px; max-height: 300px; top: 47px;"><div class="mCSB_dragger_bar" style="line-height: 30px;"></div></div><div class="mCSB_draggerRail"></div></div></div></div></div>
            </div>

我想删除所有具有以 mCSB 开头的 id 或 class 的 div 并保留内部标签(此处为

标签,但它可以是任何 HTML 标签)。

预期输出:

<div class="bi-tearm-rightdesc">
<p>
                        <span class="bold-font">Investment Decisions</span>. The Investor Information web pages are not intended to replace any information or consultation 
provided by a professional financial advisor. Other than the specific information presented in the Investor Information web pages, no information on 
our website is intended to be the basis of or should be relied upon in making an investment decision. Because the North Texas Tollway’s securities 
may involve different sources of payment and security, you should refer to the official statement for any particular security for additional 
information. Materials and information on the North Texas Tollway Authority's website are provided as a public service and intended to provide 
information on matters of public interest. Accordingly, the information in this site is not intended to serve as legal or financial advice.
                    </p>
                    <br>
                    <p><span class="bold-font">Not an Offer to Sell/Buy Securities</span>. The information provided in this website does not constitute an offer to sell 
or buy securities or the solicitation of an offer to sell or buy securities and should not be relied upon to provide specific offering information in 
connection with any issuance, sale, resale, or remarketing of bonds, commercial paper, notes, or other securities.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Dates of Documents; Estimates and Opinions</span>.All documents contained in the Investor Information section of this website 
are marked with a date and speak only as of that date, which may be prior to the date it is posted on this website. No inference should be made that 
the operations of the North Texas Tollway Authority or related entities and/or other economic conditions have remained the same since the date 
indicated. The Investor Information section of this website contains, in part, estimates and matters of opinion which are not intended as statements 
of fact, and no representation is made as to the correctness of such estimates and opinions, or that they will be realized. Any information and 
expressions of opinion herein contained are subject to change without notice.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Information is Subject to Change Without Notice and May Not Be Updated</span>. The North Texas Tollway Authority is under no 
obligation to update any information included in this website and the North Texas Tollway Authority expressly disclaims any duty to provide an update 
of any document contained in this website. The information and expressions of opinion herein are subject to change without notice and the posting of 
information on this website does not imply that there has been no change in the affairs of the North Texas Tollway Authority.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Unavailability of Website</span>.The NTTA makes every effort to keep the website up an in good running condition. However, 
NTTA takes no responsibility for, and is not liable for, the website being temporarily unavailable due to technical issues beyond its control.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Forward-Looking Statements</span>.The documents contained in the Investor Information web pages may contain "forward-looking 
statements" within the meaning of Section 21E of the Securities Exchange Act of 1934, as amended. Such statements may involve known and unknown 
risks, uncertainties, and other factors which may cause the actual results, performance, and achievements to be different from future results, 
performance, and achievements expressed or implied by such forward-looking statements. Investors are cautioned that the actual results could differ 
materially from those set forth in the forward-looking statements.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Interim Financial Information</span>.All interim financial information provided on the Investor Information web pages is 
preliminary and unaudited and subject to adjustment.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Links to Other Websites</span>.The North Texas Tollway Authority may provide links to other websites to allow investors 
independent access to other organizations whose expertise may be of value. The inclusion of any links does not imply a recommendation or endorsement 
of the views expressed within them. The North Texas Tollway Authority has not participated in the preparation, compilation, or selection of 
information on any other website, and assumes no responsibility or liability for the views, content, or accuracy of any other website referenced or 
linked through the North Texas Tollway Authority's website.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Other Information May Be Available</span>. The Investor Information section of this website is provided for the convenience 
of investors in North Texas Tollway Authority, but it does not provide a full and complete set of information that is of interest to investors. There 
may be other documents containing relevant information regarding the North Texas Tollway Authority, which may be available from other sources, 
including by request from the North Texas Tollway Authority.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Disclaimers</span>. THE NORTH TEXAS TOLLWAY AUTHORITY SHALL NOT BE HELD LIABLE FOR ANY IMPROPER OR INCORRECT USE OF THE 
MATERIALS OR INFORMATION CONTAINED ON THIS SITE AND ASSUMES NO RESPONSIBILITY FOR ANY USER'S USE OF THEM. IN NO EVENT SHALL THE NORTH TEXAS TOLLWAY 
AUTHORITY BE LIABLE, WITHOUT LIMITATION, FOR ANY DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SITE OR THE MATERIALS AND INFORMATION CONTAINED ON 
THIS SITE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE, WHETHER INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL. THIS DISCLAIMER OF 
LIABILITY APPLIES TO ANY DAMAGES OR INJURY WHETHER FOR BREACH OF CONTRACT, TORTIOUS BEHAVIOR, NEGLIGENCE, OR UNDER ANY OTHER CAUSE OF ACTION.
                    </p>
                    <p><br>THE MATERIALS IN THIS SITE ARE PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND EXPRESS OR IMPLIED. TO THE FULLEST EXTENT PERMISSIBLE, THE 
NORTH TEXAS TOLLWAY AUTHORITY DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED. THE NORTH TEXAS TOLLWAY AUTHORITY DOES NOT WARRANT OR MAKE ANY 
REPRESENTATIONS REGARDING THE USE OR THE RESULTS OF THE USE OF THE MATERIALS IN THIS SITE, OR THROUGH LINKS TO OTHER SITES, IN TERMS OF THEIR 
CORRECTNESS, ACCURACY, RELIABILITY, COMPLETENESS OR OTHERWISE.
                    </p>
                    <br>
                    <p>
                        <span class="bold-font">Indemnification</span>. To the extent permitted by applicable law, by using the North Texas Tollway Authority's website, the 
user agrees to defend, indemnify, and hold harmless, the North Texas Tollway Authority, its agencies, officers, employees, representatives, and 
agents from and against all claims and expenses, including attorneys' fees, arising out of the user's use of this site or materials and information 
contained on this site.
                    </p>
                </div>

我尝试过以下 JQuery:

$("div[class*="mCSB"]").remove();
$("div[id*="mCSB"]").remove();

但它也会删除所有子内容。

最佳答案

.contents().unwrap() 将选择元素并删除它们,但这仅适用于具有子元素的元素。

要删除那些没有子元素的元素,您只需将 .end().remove() 链接到末尾即可。

$("div[class*=mCSB], div[id*=mCSB]").contents().unwrap().end().remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="bi-tearm-rightdesc">
  <div class="bi-tearm-scrollbox customscrollbar mCustomScrollbar _mCS_1">
    <div id="mCSB_1" class="mCustomScrollBox mCS-light mCSB_vertical mCSB_inside" style="max-height: none;" tabindex="0">
      <div id="mCSB_1_container" class="mCSB_container" style="position: relative; top: -359px; left: 0px;" dir="ltr">
        <p>
          <span class="bold-font">Investment Decisions</span>. The Investor Information web pages are not intended to replace any information or consultation provided by a professional financial advisor. Other than the specific information presented in
          the Investor Information web pages, no information on our website is intended to be the basis of or should be relied upon in making an investment decision. Because the North Texas Tollway’s securities may involve different sources of payment
          and security, you should refer to the official statement for any particular security for additional information. Materials and information on the North Texas Tollway Authority's website are provided as a public service and intended to provide
          information on matters of public interest. Accordingly, the information in this site is not intended to serve as legal or financial advice.
        </p>
        <br>
        <p><span class="bold-font">Not an Offer to Sell/Buy Securities</span>. The information provided in this website does not constitute an offer to sell or buy securities or the solicitation of an offer to sell or buy securities and should not be relied
          upon to provide specific offering information in connection with any issuance, sale, resale, or remarketing of bonds, commercial paper, notes, or other securities.
        </p>
        <br>
        <p>
          <span class="bold-font">Dates of Documents; Estimates and Opinions</span>.All documents contained in the Investor Information section of this website are marked with a date and speak only as of that date, which may be prior to the date it is
          posted on this website. No inference should be made that the operations of the North Texas Tollway Authority or related entities and/or other economic conditions have remained the same since the date indicated. The Investor Information section
          of this website contains, in part, estimates and matters of opinion which are not intended as statements of fact, and no representation is made as to the correctness of such estimates and opinions, or that they will be realized. Any information
          and expressions of opinion herein contained are subject to change without notice.
        </p>
        <br>
        <p>
          <span class="bold-font">Information is Subject to Change Without Notice and May Not Be Updated</span>. The North Texas Tollway Authority is under no obligation to update any information included in this website and the North Texas Tollway Authority
          expressly disclaims any duty to provide an update of any document contained in this website. The information and expressions of opinion herein are subject to change without notice and the posting of information on this website does not imply
          that there has been no change in the affairs of the North Texas Tollway Authority.
        </p>
        <br>
        <p>
          <span class="bold-font">Unavailability of Website</span>.The NTTA makes every effort to keep the website up an in good running condition. However, NTTA takes no responsibility for, and is not liable for, the website being temporarily unavailable
          due to technical issues beyond its control.
        </p>
        <br>
        <p>
          <span class="bold-font">Forward-Looking Statements</span>.The documents contained in the Investor Information web pages may contain "forward-looking statements" within the meaning of Section 21E of the Securities Exchange Act of 1934, as amended.
          Such statements may involve known and unknown risks, uncertainties, and other factors which may cause the actual results, performance, and achievements to be different from future results, performance, and achievements expressed or implied by
          such forward-looking statements. Investors are cautioned that the actual results could differ materially from those set forth in the forward-looking statements.
        </p>
        <br>
        <p>
          <span class="bold-font">Interim Financial Information</span>.All interim financial information provided on the Investor Information web pages is preliminary and unaudited and subject to adjustment.
        </p>
        <br>
        <p>
          <span class="bold-font">Links to Other Websites</span>.The North Texas Tollway Authority may provide links to other websites to allow investors independent access to other organizations whose expertise may be of value. The inclusion of any links
          does not imply a recommendation or endorsement of the views expressed within them. The North Texas Tollway Authority has not participated in the preparation, compilation, or selection of information on any other website, and assumes no responsibility
          or liability for the views, content, or accuracy of any other website referenced or linked through the North Texas Tollway Authority's website.
        </p>
        <br>
        <p>
          <span class="bold-font">Other Information May Be Available</span>. The Investor Information section of this website is provided for the convenience of investors in North Texas Tollway Authority, but it does not provide a full and complete set
          of information that is of interest to investors. There may be other documents containing relevant information regarding the North Texas Tollway Authority, which may be available from other sources, including by request from the North Texas Tollway
          Authority.
        </p>
        <br>
        <p>
          <span class="bold-font">Disclaimers</span>. THE NORTH TEXAS TOLLWAY AUTHORITY SHALL NOT BE HELD LIABLE FOR ANY IMPROPER OR INCORRECT USE OF THE MATERIALS OR INFORMATION CONTAINED ON THIS SITE AND ASSUMES NO RESPONSIBILITY FOR ANY USER'S USE
          OF THEM. IN NO EVENT SHALL THE NORTH TEXAS TOLLWAY AUTHORITY BE LIABLE, WITHOUT LIMITATION, FOR ANY DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SITE OR THE MATERIALS AND INFORMATION CONTAINED ON THIS SITE, EVEN IF ADVISED OF THE POSSIBILITY
          OF SUCH DAMAGE, WHETHER INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL. THIS DISCLAIMER OF LIABILITY APPLIES TO ANY DAMAGES OR INJURY WHETHER FOR BREACH OF CONTRACT, TORTIOUS BEHAVIOR, NEGLIGENCE, OR UNDER ANY OTHER CAUSE OF ACTION.
        </p>
        <p><br>THE MATERIALS IN THIS SITE ARE PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND EXPRESS OR IMPLIED. TO THE FULLEST EXTENT PERMISSIBLE, THE NORTH TEXAS TOLLWAY AUTHORITY DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED. THE NORTH TEXAS TOLLWAY
          AUTHORITY DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OR THE RESULTS OF THE USE OF THE MATERIALS IN THIS SITE, OR THROUGH LINKS TO OTHER SITES, IN TERMS OF THEIR CORRECTNESS, ACCURACY, RELIABILITY, COMPLETENESS OR OTHERWISE.
        </p>
        <br>
        <p>
          <span class="bold-font">Indemnification</span>. To the extent permitted by applicable law, by using the North Texas Tollway Authority's website, the user agrees to defend, indemnify, and hold harmless, the North Texas Tollway Authority, its
          agencies, officers, employees, representatives, and agents from and against all claims and expenses, including attorneys' fees, arising out of the user's use of this site or materials and information contained on this site.
        </p>
      </div>
      <div id="mCSB_1_scrollbar_vertical" class="mCSB_scrollTools mCSB_1_scrollbar mCS-light mCSB_scrollTools_vertical mCSB_scrollTools_onDrag" style="display: block;">
        <div class="mCSB_draggerContainer">
          <div id="mCSB_1_dragger_vertical" class="mCSB_dragger mCSB_dragger_onDrag" style="position: absolute; min-height: 30px; display: block; height: 40px; max-height: 300px; top: 47px;">
            <div class="mCSB_dragger_bar" style="line-height: 30px;"></div>
          </div>
          <div class="mCSB_draggerRail"></div>
        </div>
      </div>
    </div>
  </div>
</div>

关于jquery - 如何使用 JQuery 删除具有特定单词 id 或类的 div 并保留内部内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52766294/

相关文章:

javascript - html多选表单只能选择一个选项

javascript - 如何在单击父 div 时切换无序列表中元素上的类?

javascript - 当 img src 等于 jQuery 的特定值时禁用 href

jquery - AJAX 调用中的 ERR_EMPTY_RESPONSE 随机次数

javascript - Jquery 小部件的问题

javascript - 调整 jQuery Accordion - 打开所有选项卡

javascript - 客户端选项附加到 asp.net DropDownList 控件和 ViewState 问题

javascript - 如何通过单击重新显示所有项目来否决 .hide()?

javascript - 为什么在使用 jQuery Gridly 插件后无法编辑 span?

javascript - 端到端 javascript 堆栈安全吗?