PD24
PD24

Reputation: 774

hide td with jquery based on its contents

i need to hide a TD which contains the contents "Email Address". This is because its generated via the code and i dont have the source code.

Below is the generated code:

<div id="ptkSubscribe">
        <table width="50px" style="width:50px" class="NewsletterBox">
        <tbody><tr>
            <td colspan="2"></td>
        </tr>

<input type="hidden" value="" id="txt_NL_FirstName">
<input type="hidden" value="" id="txt_NL_LastName">

        <tr>
        <td>Email Address</td>
        <td>
            <input type="text" size="13" onkeypress="enterSubmit(event);" id="txtEmailAddress"><br>
        <input type="hidden" value="" id="txtCaptcha"><br></td>
    </tr>
    <tr>
        <td align="left" colspan="2"><input type="button" onclick="clickSubmit();" id="cmdSubmit" value="Submit"></td>
    </tr>
    </tbody></table>
  </div>

Upvotes: 1

Views: 1536

Answers (1)

T. Stone
T. Stone

Reputation: 19495

jQuery has a :contains selector which will select elements if they contain text. It's likely a lot slower than regular selectors, so you'll want to specify a target region (the table) to make it a bit more efficient.

Something along the lines of this should work...

$('td:contains(Email Address)', '#ptkSubscribe').hide();

:contains reference

Upvotes: 4

Related Questions