I think I'm really close. How can I get the "newtitle" variable to match what is typed in the Title field?
See exactly: https://jsfiddle.net/a0cj8xmy
jQuery:
var newtitle = 'This works but isn\'t what I type';
//var newtitle = $('$title-field').text(); // This doesn't work
//var newtitle = $('$title-field').html(); // This doesn't work
//var newtitle = $('$title-field').val(); // This doesn't work
$('#title-field').bind('keyup', function(){
$('#body-field').html($('#body-field').html().replace(/title=""/g,'title="'+newtitle+'"'));
});
HTML:
Title:<br>
<input type="text" id="title-field" placeholder="Type here!">
Body:<br>
<textarea id="body-field" name="body[und][0][value]" cols="60" rows="10">
<a href="" title=""><img src="" class="" /></a>
</textarea>
$title-fieldby#title-field.val()returns a string, which is copied (and not a reference). You will need to fetch the new title in the listener