4

I want get the following element style and append them to input value.

append CSS property value to input value, where property is equal to input name.

Here is my div from where I want to get style

<div class="styler">
   <h3 style="color:#555;font-size:30px;font-family:'open sans';">
        I am Heading
   </h3>
</div>

And this is the input where I want to append my styles

<div class="myStyle">
   <input name="color" />
   <input name="font-size" />
   <input name="font-family" />
</div>
1
  • $(documnet).ready(function(){ $(input[name]).attr('style', $('.styler h3').attr('style')) });. Is this you are looking for. Commented Jul 16, 2013 at 5:05

2 Answers 2

6

Try

var h3 = $(".styler h3");
$('.myStyle input').each(function(){
    this.value = h3.css(this.name);
})

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for answering. I love your solutions, small and effective
0

You may try this too

$('.myStyle input').val(function(i){ 
    return $('.styler h3').attr('style').split(';')[i].split(':')[1]; 
});

DEMO.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.