0

I'm working with Canvas and I'm trying to add centered text dynamically on a picture.

I read on this topic (How to add text on image using Javascript and Canvas), that I have to put some jQuery in my code. I tried but I did not succeed because I don't have a lot experience in jQuery.

You can find the example I made on the JSFiddle link below.

https://jsfiddle.net/ParkerIndustries/t3rao9hL/14/

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
ParkerIndustries
  • 171
  • 2
  • 15
  • Sorry, the mistake was in the fillText function. If you want to center horizontally, put width/2 in fillText as x position. So ```context.textAlign = 'center';``` works but, I just set a bad position. – ParkerIndustries Aug 18 '19 at 02:03

1 Answers1

1

If you have to add in jQuery to your code ( besides having the jquery.min file loaded ), you precursor any code with the "$" symbol and then the element you are identifying ( wrapped in parenthesis ). In your case:

 $(context)

since you've already identified your element. Then after that there are a couple ways to change css using jQuery.

$(context).css({ 'display', 'none' });
$(context).addClass('changed');

If you don't have an identifier, just put it in quotes:

$('#context').addClass('changed');

For JavaScript, Clarity answered that in the comment above.

Keith
  • 4,059
  • 2
  • 32
  • 56