0

I need to remove the text Private: in value.
I tried following codes, but it doesn't remove the text.
Would you please let me know how to remove it?

Existing code (created using plugin):

<form method="post" class="dwqa-content-edit-form">
     <p>
          <input type="text" name="question_title" value="Private: about your question" tabindex="1">
     </p>
</form>

Codes I tried:

jQuery('.dwqa-content-edit-form p input').text(function () {
    return jQuery(this).text().replace(/Private: /g, '');
});

jQuery('.dwqa-content-edit-form p input[type=text]').each(function() {
        if (jQuery(this).val() === "Private: ") {
            jQuery(this).remove();
        }
    });

Thank you.

isbe
  • 233
  • 2
  • 12

1 Answers1

1

You can use the val function to get the current value of the input field and use it again to apply the modified value without the "Private: " string. Example below.

jQuery('.dwqa-content-edit-form p input[type=text]').each(function() {
        console.log($(this).val());
        var value = $(this).val().replace("Private: ", '');
        $(this).val(value);
 });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

<form method="post" class="dwqa-content-edit-form">
     <p>
          <input type="text" name="question_title" value="Private: about your question" tabindex="1">
     </p>
</form>
iismaell
  • 623
  • 5
  • 10