Why it isn't working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why it isn't working

Could you look my codes and tell me my wrong :) https://code.sololearn.com/W7a7uRkrdBo4/#

31st May 2017, 8:51 PM
Serhat Merak
Serhat Merak - avatar
11 Answers
+ 6
/* Because you do many mistakes ^^ Guessing you expect to remove the previous <textarea> element from the red cross: In JQuery, before() method is used to insert some content before an element, not select previous sibling... to select previous sibling element, rather use prev() method. But then you will remove only the <textarea> ( previous sibling ) element :P You must remove also the red cross, or use one more container handling both <textarea> and red cross, then deleting the parent of red cross ( parent() method instead of prev() one ) to remove both at same time... However, the other big mistake is at time of appending new <textarea>/red cross pair: the red cross don't handle the onclick event you've defined at load time... you need to do so after appending it ( only for the new/last element inserted, else you will declare many onclick events for already setted ones, and getting errors/unexpected behaviours ): */ $(function() { $("#arttir").on("click", function() { var elem = $("<textarea rows='1' cols='12' class='txt'></textarea>"); $("#textDivi").append(elem); $("#textDivi").append("<input type='button' value='ร—' class='Kapa'>"); /* use :last-child pseudo-selector to only affect last inserted element */ $(".Kapa:last-child").on("click", function() { $(this).prev().remove(); $(this).remove(); }); }); $(".Kapa").on("click", function() { $(this).prev().remove(); $(this).remove(); }); }); /* Anyway, as you can see in above code, indenting allow better readability: keep the habits to do like this, for programming/scripting code as for declarative code ( html )... And rather posting your profile link ( it's accessible by cliking on you avatar picture ^^ ), post the direct link to your related code ( inside code playground, you can get it by cliking on the share icon ). https://code.sololearn.com/W7a7uRkrdBo4/?ref=app */
1st Jun 2017, 4:22 AM
visph
visph - avatar
+ 5
( it's not a good way to do of posting code and deleting it: future readers will not have the question context ^^ Will you have the bad idea of deleting your question too, with no respect of answerer time passed for you? :P Rather upvote useful answers, even set one as best answer, and keep question and related code for future readers... )
1st Jun 2017, 4:29 AM
visph
visph - avatar
+ 4
"Done" means I have do ( done ) your request ( so it's already changed in my "answer" to your "question" )
1st Jun 2017, 5:04 AM
visph
visph - avatar
+ 3
Sorry: the link to your code seems not work ( probably because you just delete it ^^ )
1st Jun 2017, 4:24 AM
visph
visph - avatar
+ 3
<< could you change your link please I loaded again ๐Ÿ˜Š >> Done... But you could edit the one in your question ;)
1st Jun 2017, 4:57 AM
visph
visph - avatar
0
Thank you very much ๐Ÿ˜Š
1st Jun 2017, 4:23 AM
Serhat Merak
Serhat Merak - avatar
0
๐Ÿ˜‚ because I did Sorry ๐Ÿ˜Š
1st Jun 2017, 4:27 AM
Serhat Merak
Serhat Merak - avatar
0
Ok ๐Ÿ˜Š I will upload again ๐Ÿ˜Š
1st Jun 2017, 4:39 AM
Serhat Merak
Serhat Merak - avatar
0
could you change your link please I loaded again ๐Ÿ˜Š
1st Jun 2017, 4:55 AM
Serhat Merak
Serhat Merak - avatar
0
I don't know so much english If I rude , I am sorry ๐Ÿ˜Š
1st Jun 2017, 5:03 AM
Serhat Merak
Serhat Merak - avatar
0
Oh sorry Okay I didn't want to post it ๐Ÿ˜‚
1st Jun 2017, 5:06 AM
Serhat Merak
Serhat Merak - avatar