11 Replies - 597 Views - Last Post: 18 November 2011 - 05:14 AM

#1 itdoell  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 239
  • Joined: 13-January 11

Get textarea html without using a wrapper?

Posted 17 November 2011 - 09:22 PM

I want to get all the code associated with a textarea (or anything) so that I can essentially "reset" it. The solution can be either Javascript or jQuery, I'm comfortable with both, I just don't know how to do it.

To explain, a bit more, I'm essentially going to use .remove() on it so that I can get rid of all the associated jQuery, then I'm going to replace it with the exact same thing so that it "resets" itself. However, I do not know how to get the code of something unless it has a wrapper around it, and I'd like to avoid adding one if I can.

So, is it possible to do this without using a wrapper? I'm up for any and all suggestions, thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Get textarea html without using a wrapper?

#2 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 04:06 AM

Can you please explain a bit more clearly, if possible with an example or something? What do you mean by I want to get all the code associated with a textarea (or anything) so that I can essentially "reset" it.? Textarea is a HTML element, what do you mean by getting its jQuery?
Was This Post Helpful? 1
  • +
  • -

#3 itdoell  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 239
  • Joined: 13-January 11

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 04:32 AM

View Postcupidvogel, on 18 November 2011 - 04:06 AM, said:

Can you please explain a bit more clearly, if possible with an example or something? What do you mean by I want to get all the code associated with a textarea (or anything) so that I can essentially "reset" it.? Textarea is a HTML element, what do you mean by getting its jQuery?


By removing the jQuery associated with it, I mean just that, I am using a plugin for an expanding textarea however a glitch occurs regarding resizing it after the textarea has been cleared and I want to revert it back to the old size. So in order to get around this glitch, I'm simply going to remove the existing textarea and all associated jquery (as in the jquery effecting the size of it) by using .remove() and then I am going to recreate the exact same textarea.

So for example, if the textarea code is...

<textarea name="newposttext" id="newposttext" onblur="if(this.value.length == 0) this.value='Message...';" onfocus="if(this.value == 'Message...') this.value='';">Message...</textarea>


I want to grab that exact code before removing it, then remove it, then recreate that box. I have dynamic ID's for my textarea which is why I need a JS solution that involves grabbing the code. I know I can do this easily by just wrapping it in a div or something then just using wrap.html() however I don't want to have to do that because it seems unnecessary. I imagine there must be a way to grab all the code of an element without having to grab it from inside a wrapping div.

So that's what I'd like to know how to do, assuming this is possible.

This post has been edited by itdoell: 18 November 2011 - 04:38 AM

Was This Post Helpful? 0
  • +
  • -

#4 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 04:44 AM

I don't understand, why are you putting the jQuery inside the textarea tag? Just put it inside the script tag at the top of the page within head, so that once you re-insert the textarea, the jQuery automatically apply to it and revert it to the same size?

By the way, if you have dynamic id's, you better attach events to the textarea using live or delegate.

This post has been edited by cupidvogel: 18 November 2011 - 04:40 AM

Was This Post Helpful? 1
  • +
  • -

#5 itdoell  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 239
  • Joined: 13-January 11

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 04:51 AM

I'm not putting jQuery inside the tag... You don't seem to understand, there are jQuery functions affecting my textarea tags. So in order to completely remove the jQuery affecting it, I will use the .remove() method and then replace it, as stated on the jquery website...

"In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed."

So, to remove the associated jquery, aka the jquery that is bound to this element, I remove it, then I will recreate it.

View Postcupidvogel, on 18 November 2011 - 04:44 AM, said:

By the way, if you have dynamic id's, you better attach events to the textarea using live or delegate.


The dynamic ID's I was referring to are done in PHP, not JS.
Was This Post Helpful? 0
  • +
  • -

#6 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 04:53 AM

Then bind the events to the textarea via live or delegate. The jQuery will automatically attach to the textarea when it is re-inserted.
Was This Post Helpful? 1
  • +
  • -

#7 itdoell  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 239
  • Joined: 13-January 11

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 05:03 AM

View Postcupidvogel, on 18 November 2011 - 04:53 AM, said:

Then bind the events to the textarea via live or delegate. The jQuery will automatically attach to the textarea when it is re-inserted.

You're really just not understanding this. Binding the jQuery isn't the issue here, at all. I'm not having trouble binding the jQuery. There is an issue with a plugin I'm using which is causing a glitch (the textarea randomly reverts back to the old size after the form as been submitted and cleared). So in order to fix this glitch without having to do a lot of modifications to the plugin, I am simply going to remove the old textbox and create a new one after the form as been submitted.

My only question I have is how I grab an element. Something similar to the .html() method, except that only grabs the children of an element, and not the element itself. So I'm just curious to know if there is a way I can grab that element without having to wrap a div or something around it and then use .html()
Was This Post Helpful? 0
  • +
  • -

#8 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 05:05 AM

Ummm, I am not getting you either! :online2long: You can use .clone(True), see if it works.
Was This Post Helpful? 1
  • +
  • -

#9 itdoell  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 239
  • Joined: 13-January 11

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 05:12 AM

View Postcupidvogel, on 18 November 2011 - 05:05 AM, said:

Ummm, I am not getting you either! :online2long: You can use .clone(True), see if it works.

Exactly what I wanted man. (I think) I'll try using .clone(), I had forgotten all about it.
Was This Post Helpful? 0
  • +
  • -

#10 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 05:12 AM

It works?
Was This Post Helpful? 1
  • +
  • -

#11 itdoell  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 239
  • Joined: 13-January 11

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 05:13 AM

View Postcupidvogel, on 18 November 2011 - 05:12 AM, said:

It works?

Haven't tried yet, in fact I'm going to bed and will try in the morning. (it is 4:13 am here in Seattle)

Thanks a bunch for your help, much appreciated.
Was This Post Helpful? 0
  • +
  • -

#12 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Get textarea html without using a wrapper?

Posted 18 November 2011 - 05:14 AM

Sorry, didn't see your reply. Don't forget to put True inside it, otherwise it won't replicate the jQuery! :bananaman:

Cool. I code until early morning too. Do let me know whether it works or not!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1