/    Sign up×
Community /Pin to ProfileBookmark

js remove element

hi everybody,

i really appreciate if somone could help me ? i try to google few days but no luck to find what i want, and since im kinda new in js (jquery) i need some help, so

i have a xml file that i will load inside a div on the website, and one of the element is a function with some content like
<function> xxxx</function>
<function>ppppp</function>……

what i would like to do is double click on a text xxxxx and the element function inside the div will delete without the xxxx

result:

xxxxxx
<function>ppppp</function>

so far is my code:

$(“.containtext”).dblclick(function(){
$(“function”).remove().text(txt);
})

but this code will delete all the element function from the div even with his contents

thanks in advance

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootApr 25.2016 — You need to ask in the JQuery forum, see my signature. Link to it there.
Copy linkTweet thisAlerts:
@Ay__351_eApr 25.2016 — If I understan

I tried empty()


&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(function(){

$(".containtext function:first").dblclick(function(){
$("function:first:first-child").empty();
alert(document.body.innerHTML);
});
//$("p:first-child").css("background-color", "yellow");
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="containtext" style="height:100px;width:300px;border:1px solid black;background-color:yellow;"&gt;
&lt;function &gt;xxxxxxxxxxxxx&lt;/function&gt;
&lt;function&gt;ppppppppppppp&lt;/function&gt;
&lt;/div&gt;

http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_dom_empty
&lt;br&gt;
http://www.w3schools.com/jquery/jquery_selectors.asp
&lt;br&gt;
http://www.w3schools.com/jquery/jquery_dom_remove.asp
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@tanfr079authorApr 26.2016 — ah ok thanks ?
×

Success!

Help @tanfr079 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...