Add onchange attribute to textarea via css

Posted on 2006-06-01
Last Modified: 2008-02-26
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.

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

Any ideas?

Question by:k2consulting
    LVL 15

    Expert Comment

    Pretty sure you are going to need to use javascript for this.  CSS is for setting up the layout of the page.

    LVL 5

    Accepted Solution


    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){
           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


    Author Comment

    Works perfectly.  Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Most web designers often experience crossbrowser issues during interface design / development.  On common problem is with Internet Explorer due to its rendering discrepancies between previous versions.  Here are some techniques I use to help avoid c…
    When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
    In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now