Forum Moderators: open

Message Too Old, No Replies

jquery, how to track down an error

         

csdude55

8:15 pm on Aug 2, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The jQuery forum looks to have stopped working about a year ago, sorry for all of the jQuery questions all of a sudden!

I have a short script that's not working, and I can't quite figure out why:

$(function() {
$('[data-richbutton=Bold], [data-richbutton=Italic], [data-richbutton=Underline], [data-richbutton=Cut], [data-richbutton=Copy], [data-richbutton=Paste]')
.on('mousedown', function(e) {

// I need the B, I, U, C, or P instead of the whole word
var thisButton = $(this).data('richbutton').charAt();

console.log('a - ' + thisButton);

$('[data-richcont="' + thisButton + '"]').toggleClass('richbuttonOff, richbuttonOn');

console.log('b - ' + thisButton);

changeSpan(e, $(this).data('richbutton'));

console.log('c - ' + thisButton);
});
});


If I remove the "var thisButton..." and "toggleClass" lines then changeSpan() works fine, but when they are active then it doesn't work. I don't get any errors in the console and the three test lines (a, b, and c) all show up, but I don't get the expected result.

I tried using the .error() function like so:

$('[data-richcont="' + thisButton + '"]')
.toggleClass('richbuttonOff, richbuttonOn')
.error(function() {
console.log('error here');
});


but that just threw an error that .error wasn't recognized.

Any other suggestions on finding the exact problem?

csdude55

8:17 pm on Aug 2, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Side note, the original script used this instead of a separate "thisButton":

$('[data-richcont="' + $(this).data('richbutton').charAt() + '"]')
.toggleClass('richbuttonOff, richbuttonOn');


I split it out for testing purposes. Once I get it working properly I'll probably merge it back to a one-liner.