0

Either my javascript or my template is broken.

This is my javascript to change error messages. I cannot change my template, because it is not accessible.

<!-- CHANGE ERROR MESSAGE -->
<script language="JavaScript">

  $(function() { 
    $.ajaxSetup({complete: function() { 
      $(".errorExplanation ul li:contains('Password and email do not match')").ReplaceWith('Password does not match');}}) 
  });

</script>

This is the part of the website that refuses to be translated:

The code of the page

What am I doing wrong?

2
  • 1
    .replaceWith the r should be lowercase. Commented Apr 15, 2016 at 20:09
  • Does not work. I don't think lowercase or uppercase has anything to do with it. I think the error code 'password and e-mail..' are part of another section that I do not understand (yet). Commented Apr 15, 2016 at 20:11

3 Answers 3

1

You might consider just using a more generalized selector such as span.error-message:contains('...') and just using jQuery's text() function to set the content :

$("span.error-message:contains('Password and email do not match')").text('Password does not match');

If you need it to be more specific, you could use an identifier like #pattern from your example code :

$("#pattern span.error-message:contains('Password and email do not match')").text('Password does not match');

You can see a very basic example demonstrated below :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <pre>Original</pre>
  <span class='original-error-message'>
        Password and email do not match
  </span>
  <pre>Replaced</pre>
  <span class='error-message'>
        Password and email do not match
  </span>
  
<script language="JavaScript">
    $(function() { 
      // Replace any spans with class 'error-message' that contain
      // your specific text
      $("span.error-message:contains('Password and email do not match')").text('Password does not match');
    });
  </script>
</body>
</html>

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply. Unfortunately it is not working. It might be the .html part, but i really think it is some section.
I've updated it to use text(), which is more appropriate since you are just using plain text and added an example, which works.
Works like a charm, thank you so much! Have a great weekend.
0

Use the .text() method to replace the text, make it simpler:

$(function(){
    $("span.error-message").text('Password does not match');
})

Comments

0

try this,

$('.error-message span').html('Password does not match');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.