[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 562
  • Last Modified:

Add onchange attribute to textarea via css

How do I add an attribute via css?
What I need to do is add a onchange="copy(this)" to all textarea's within the question div.

eg.
<div class="question">
    <textarea onchange="copy(this)">Lorem ipsum</textarea><div></div>
</div>

Any ideas?

Dan
0
k2consulting
Asked:
k2consulting
1 Solution
 
tim_csCommented:
Pretty sure you are going to need to use javascript for this.  CSS is for setting up the layout of the page.

0
 
shaggy_the_sheepCommented:
Hi

You wont be able to do it with CSS, JavaScript on the other hand should be able to do it.

function addFunction(){
var div = document.getElementsByTagName('div');
for(var x in div){
   if(div[x].className=='question'){
       var inner = div[x].innerHTML;
       var newInner = inner.replace(/<textarea/gi,'<textarea onchange="copy(this)" ');
       div[x].innerHTML = newInner;
       }    
   }
}

<body onload="addFunction()">
That should do it for ya

Richard
0
 
k2consultingAuthor Commented:
Works perfectly.  Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now