Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perfect

Dongyun Cho
Dongyun Cho
2,256 Points

reloading after drawing.

I want to reload after I finish drawing.

But I'd like to reload only "canvas". when I write code like this, instead of code in workspace,

$canvas.location.reload; it doesn't work. why? and the second question, is it ok if I write javascript and jquery at the same line? Because jquery is jsut javascript, I think?

$('#reset').click(function(){
  document.location.reload();
})
    <div id='buttons'>
        <button id="revealColorSelect">New Color</button>
    <button id="reset">Reset</button> 
    </div>

https://teamtreehouse.com/workspaces/25145512

1 Answer

Robert Leonardi
Robert Leonardi
17,151 Points

Hi Dongyun CHo,

Do you mean you want to clear the canvas without reloading the page?

let $canvas = $("canvas"); let context = $canvas[0].getContext("2d"); context.clearRect(0, 0, $canvas.width(), $canvas.height());

Yes you can write jquery and javascript in the same line

best of luck