Reputation: 29
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:
What am I doing wrong?
Upvotes: 0
Views: 224
Reputation: 1530
try this,
$('.error-message span').html('Password does not match');
Upvotes: 0
Reputation: 76557
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>
Upvotes: 1
Reputation: 252
Use the .text()
method to replace the text, make it simpler:
$(function(){
$("span.error-message").text('Password does not match');
})
Upvotes: 0