ParkerIndustries
ParkerIndustries

Reputation: 171

How to add text dynamically text using both JavaScript and jQuery?

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/

Upvotes: 0

Views: 178

Answers (1)

Keith
Keith

Reputation: 4147

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.

Upvotes: 1

Related Questions