Download content inside the div but removed the html elements inside

Hi Everyone!

I need help in creating a function which I can download the content in a specific DIV element but removed the HTML element inside the Div content. Please help me. Here’s a fiddle for your reference:

https://jsfiddle.net/6qsvqrh1/1/

In my example I have a Div id=“textareaClone” and inside it, is an html element <span id="target-firstname-2"></span> I want to remove that element but remain the text inside before I download the content.

Thanks in advance,

Are you certain you want to use unwrap?

That removes the parent element so your example would originally look something like

<section> 
  <removed div> 
    <span></span>
  </removed div>
</section>

I think you may looking for “text()

It can be used both to “get” and to “set” text values.

If you want the text inside return the get, if you don’t return an empty string

I am not certain using unwrap. That is just my example to achieve my explanation. Thank you for answering my question. If this is not too much can you give me an example of how can I accomplish your answer? Si I want to download the text inside a Div but remove the element inside it. Thanks :smile:

The documentation I linked to has a few good examples you should look at.

But I’m thinking instead of
$("span#target-firstname-2").unwrap();

something like
$("span#target-firstname-2").text();

Hi!

hmm. so what will be the output? I mean will it remove the <span id="target-firstname-2"></span> when I hit on the button and will the text inside the span element retain? I’m experimenting on .text(); now. Thanks. :smile:

I have another problem. When I click on the download button it just remove some element but the download function is not working. :disappointed_relieved:

Hi, I can’t think of a way to use .text(); and remove a specific element inside the div.

hi!

I was able to remove the element I am targeting. But how can I bring it together with another function? I have 2 buttons in this example: https://jsfiddle.net/vt34mh6p/

So I want the download file button and remove element button as one function. I want download button to remain. so what will happen is I’m gonna type a text first then I will hit on the download button. Before the selected content will download the file, the remove element function will run first. Any idea?

Thanks in advance.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.