0
Why it isn't working
Could you look my codes and tell me my wrong :) https://code.sololearn.com/W7a7uRkrdBo4/#
11 odpowiedzi
+ 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
*/
+ 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... )
+ 4
"Done" means I have do ( done ) your request ( so it's already changed in my "answer" to your "question" )
+ 3
Sorry: the link to your code seems not work ( probably because you just delete it ^^ )
+ 3
<< could you change your link please I loaded again 😊 >>
Done...
But you could edit the one in your question ;)
0
Thank you very much 😊
0
😂 because I did Sorry 😊
0
Ok 😊 I will upload again 😊
0
could you change your link please I loaded again 😊
0
I don't know so much english If I rude , I am sorry 😊
0
Oh sorry Okay I didn't want to post it 😂