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 trialmsdsmd sm,dfsadf
1,124 PointsPlease, someone, help. This is very short line of code
""
5 Answers
Alan Brown
20,524 PointsHi, You intentions are not clear. When I read your comments in the code I get the impression you want to stop the browser highlighting the text they are selecting by clicking and dragging across the page. Is this correct?
msdsmd sm,dfsadf
1,124 PointsYes
Alan Brown
20,524 PointsWhat outcome are you trying to achieve? Is it to stop a user copying the text, or just to visually not show the selection?
msdsmd sm,dfsadf
1,124 PointsThank you so much for trying to help, but I finally solved it.
msdsmd sm,dfsadf
1,124 Points<!DOCTYPE html>
<html>
<body>
<div style="background:red;"></div>
<script>
let num = 200
const div = document.querySelector('div')
div.style.width = div.style.height = `${num}px`
</script>
</body>
</html>
/*
Can someone tell me why the div is square,
I think it should be empty
div because
I only set the width, not the height.
*/
Alan Brown
20,524 PointsThis second question, βCan someone tell me why the div is square, I think it should be empty div because I only set the width, not the height.β is straightforward.
div.style.width = div.style.height =
${num}px``
You are setting the width to the height, which you are setting to your number in pixels. So yes, you are setting the width and the height.
ja5on
10,338 Pointsja5on
10,338 PointsTake a look at my answer. I supplied where i found the answer too (i dont pretend to know and remember everything lol :-)
https://teamtreehouse.com/workspaces/41639381#