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

Konrad Pilch
Konrad Pilch
2,435 Points

Why creating player doens't work? - jQuery

Why adding player doens't work?

codepen

3 Answers

Tushar Singh
PLUS
Tushar Singh
Courses Plus Student 8,692 Points

Ok I couldn't understand what you ere doing with you css, I just cleaned it.

var player = $('<div></div>').css({'width': plWidth + 'px',
 'height':plHeight + 'px',
 'border-radius': plRadius + '%',
 'background-color': plColor});

and obviously working now :wink:

Konrad Pilch
Konrad Pilch
2,435 Points

Yeah, Iv just foudn this http://www.w3schools.com/jquery/css_css.asp

I did the CSS part thingyu wrong. Good timing though! :)

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

Now you might want to try --

I added a red square now I want to add a black square, it should give me an option whether to replace the previous item or not? If I say "No"-- I will have 2 images, I guess you get the point.I mean it should be fun now.

Konrad Pilch
Konrad Pilch
2,435 Points

Not 100% sure what you mean but if im correct:

Not im going to do, you can click on any item on in the body, and then change its color , size etc.. and move it around. Thats what I want to do now. Well, first i need to make it selectable, and movable. if you mean something like that.

Konrad Pilch
Konrad Pilch
2,435 Points

Not 100% sure what you mean but if im correct:

Not im going to do, you can click on any item on in the body, and then change its color , size etc.. and move it around. Thats what I want to do now. Well, first i need to make it selectable, and movable. if you mean something like that.

Tushar Singh
PLUS
Tushar Singh
Courses Plus Student 8,692 Points

I am working on that damn tic tac toe, seriously it's hard lol. Right now I am just planning and I can see a lot of "if"s in my mind already :O

Konrad Pilch
Konrad Pilch
2,435 Points

Hmm, remember that theres also 'switch'. I'm going to do next a calculator, like you, and basically go throw your codepen :D Wow, this is such a nice learning experience with you, im glad we are in the same sea :D

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

I don't know why but I don't feel comfortable with switch hehehe.I learned today a lot fro you:D

Don't make a stupid calculator, it's easy really. Why don't you work with an api now?

Tushar Singh
PLUS
Tushar Singh
Courses Plus Student 8,692 Points

Take an example.

I used width=100, height=100, border-radius=0 and color=red; ------> a red square

Again I thought no red is a stupid color, I want a black square--width=100, height=100, border-radius=0 and color=black;

I will get now 2 squares now but I don't need the red square anymore, I want to remove it but you are not giving me anything to remove the red square, instead I am stuck with 2 colors.

I should have an option whether I want both my shapes OR do I want to remove my previous shape!!!

Konrad Pilch
Konrad Pilch
2,435 Points

I had a bad start of the day, now is 21:20 and well, im going now from 1-2hours now maybe. So yeah. Tomorrow i will tackle a lot of stuff i have in mind :D

Yes! I'm stuck on that. Im really confused on how to select the specific element, adding the class 'selected', and then performing action with a button delete.

Could you help me please on how can i select the element when added it?

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

Well I guess you can

1) when you append your player, you can add a class as well by addClass

2) you can create a button "X"(to delete an item) and use "mousemove" and display that button(position absolute)

3) and add a mouseleave function as well so that the "X" disappears when the mouse moves away from the image.

4) by clicking "x", well we can then use $(this).hide().

I mean that's a plan lol and it should work(I think :P)

Konrad Pilch
Konrad Pilch
2,435 Points

Wow, nice idea!

But each class shoudl be unique. How can i make the class unique? Im sure a for loop or something like that , to give the player id of 1, and the next one id of 2, or something?

I understand you, you did a similar effect on the wiki with the hover thingy :) i like the idea!

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

Well how can you add really different ids to every new shape?? I can have 100 shapes if I want, I don't think that's even possible lol.

How can you define a unique class/id for every image? Although, we can use $(this) to manipulate it.

Konrad Pilch
Konrad Pilch
2,435 Points

How do we select the image using this? I don't know how to get the appended player.

So now that we have 2shapes, how do i on click select it, the specific one? how do i target it in the first place? Like what do i do ? because i cant write just $(this) because it wont know what is 'this'. If you get me.

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

Working on it, let's take rest today lol because I don't know what but we are missing something. We will figure it out tomorrow, my brain has stopped working now hehehe, 2:33am here :p