Cann0nF0dder
Cann0nF0dder

Reputation: 554

Jquery remove text from span

I'm new to JQuery and really struggling how to perform the query I want.

I'm using SharePoint, and the when using the External Data Column and set it to required field, the error message always appears until you fill in the data. Unlike other type columns where they only appear after you click OK/Save and not filled in the data. Therefore I need to remove the error message text just from these type of columns.

I assume I need to search for span within the .ms-error class that contains the words 'External Data' and hide it.

From using IE developer toolbar, I've identified the area.

 <table class="ms-usereditor" id="ctl00_m_g_05df537a_596b_443a_a11e_764069facec8_ctl00_Field_External_539c53fe_8334_43c8_b089_cc28d7895e68_Picker_OuterTable" style="border-collapse: collapse;" border="0" cellSpacing="0" cellPadding="0">
    <tbody>
     <tr>
     <td colSpan="3">
       <span class="ms-error" id="ctl00_m_g_05df537a_596b_443a_a11e_764069facec8_ctl00_Field_External_539c53fe_8334_43c8_b089_cc28d7895e68_Picker_errorLabel">
           Text - You must specify a value before using the Check button. You can also use Select button to choose External Data.
        </span>
      </td>
      </tr>
    </tbody>
</table>

Please can someone help me with the JQuery.

Upvotes: 11

Views: 75777

Answers (3)

Ekas Preet Singh
Ekas Preet Singh

Reputation: 61

Here's more optimised and faster approach:

$(".ms-usereditor span[class^='ms-error']:contains('External Data')").hide()

And additionally, this syntax works as a charm when you require a sort of regex pattern to find all matching nodes or nodes with similar classnames. Suppose, you need to find something .ms-error-1 .ms-error-abc. So, same syntax works and even better you could do like this:

$(".ms-usereditor span[class^='ms-error-']:contains('External Data')").hide()

Upvotes: 0

Moin Zaman
Moin Zaman

Reputation: 25445

$('span.ms-error:contains("External Data")').hide();

If you know for sure that these span's are inside a certain table or a div then target it specifically inside those to make the script perform better.

eg.

$('.ms-usereditor span.ms-error:contains("External Data")').hide();

Upvotes: 5

jbabey
jbabey

Reputation: 46647

var spans = $('.ms-error');

spans.text(''); // clear the text
spans.hide(); // make them display: none
spans.remove(); // remove them from the DOM completely
spans.empty(); // remove all their content

Upvotes: 47

Related Questions