Xenyal
Xenyal

Reputation: 2213

Targeting a specific class inside an id using jQuery

I have the following id of a table element:

<tr id="_IWID_Filters_included">
    <td width="20%" class="lotusFormLabel lotusFormFieldRow lotusNowrap"> </td>
    <td class="lotusFormFieldRow"> </td>
</tr>

I want to append a string into the td class "lotusFormFieldRow". Currently, I only know how to append a string targeting $("#_IWID_Filters_included").append("string"); which only appends the string to the end of IWID before /tr. Any ideas on how I can do this?

Currently, I have :

    $("#_IWID_Filters_included").append(
        "<td class = 'lotusFormFieldRow'>" + 
        "<div id='filter_" + current_index + "'>" +
        "Filter name: <select id = 'dimensionName_" + current_index + "' class='lotusText'></select>" + 
        "Filter value: <select id ='dimensionId_" + current_index + "' class='lotusText'></select>" +
        "<button type='button' id='remove_btn_" + current_index + "' onclick='filter_forms.remove_filter_form(" + current_index + ")' style='margin-top: 5px; margin-bottom: 5px;'>Remove filter</button>" +
        "</div>" + 
        "</td>" + "<td width='7%' class='lotusFormFieldRow'>" + "</td>" 
    );

However, instead of having the td class be part of the string, it needs to be inside IWID_Filters_included so that I can just put the last td width at the end. The main issue right now is that every time I click "Add filter", the td width is appended which is disrupting the spacing of the table; hence, why I need a way to target td class = lotusFormFieldRow specifically.

Upvotes: 1

Views: 94

Answers (3)

Some_random_coder
Some_random_coder

Reputation: 147

YO you can append string using: var string = "something" + "something else". GG

Upvotes: 1

Aaron
Aaron

Reputation: 550

Append adds after the selector - .text() or .html() will insert into the selector, depending if you need a string or markup.

$(".lotusFormFieldRow").text("string");

Upvotes: 1

CRABOLO
CRABOLO

Reputation: 8793

This should work

$('#_IWID_Filters_included .lotusFormFieldRow').append('I am appending this string now!');

Helpful Tip: If you wanted to append something BEFORE the other content in that specified element use .prepend instead of .append

Upvotes: 1

Related Questions