开发者

Find and replace in div table using jQuery?

开发者 https://www.devze.com 2023-03-15 04:53 出处:网络
I have a text \"First Name (Given Name, Forename):\" that needs to replaced with \"Something\" using jquery. Please see below text.

I have a text "First Name (Given Name, Forename):" that needs to replaced with "Something" using jquery. Please see below text.

  <div id="ctl00_m_g_23e3c2e9_71b9_464f_9ad3_46a603eb384f_ctl00_PanelSearch" 
               sizcache="3" sizset="0">
    <table width="100%" sizcache="2" sizset="0">
        <tbody sizcache="1" sizset="0">
            <tr sizcache="0" sizset="0">
                <td style="width: 40%;">
                    First Name (Given Name, Forename): //replace with "Some开发者_StackOverflowthing"
                </td>
            </tr>
        </tbody>
    </div>

How to do this?


If you put a class on your td (tdContent) you could do something like this:

$("#ctl00_m_g_23e3c2e9_71b9_464f_9ad3_46a603eb384f_ctl00_PanelSearch .tdContent").html("New Content goes here");

If you do not want to use a class make your selector

$("#ctl00_m_g_23e3c2e9_71b9_464f_9ad3_46a603eb384f_ctl00_PanelSearch td:first")

The simplest would be to give the td an id:

$("#tdID").html("content");


You'll want to find the DOM element and then use jQuery's text (or html) method.

$('div#ctl00_m_g_23e3c2e9_71b9_464f_9ad3_46a603eb384f_ctl00_PanelSearch td').text('Something')


You're looking for contains.

var text = $('td:contains("(Given Name, Forename)")');
text.html(text.html().replace('(Given Name, Forename)', "Something"));

update

$('td:contains("Company Name")').html('Something')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号