JQuery - get .css () value and add to input value

I want to get the following style of an element and add it to the input value.

add the value of the CSS property to enter value , where the property is equal to the input value of name .

Here is my div where I want to get the style from

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

And this is the entry where I want to add my styles

 <div class="myStyle"> <input name="color" /> <input name="font-size" /> <input name="font-family" /> </div> 
+4
source share
2 answers

Try

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

Demo: Fiddle

+6
source

You can try it too

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

Demo.

0
source

Source: https://habr.com/ru/post/1491567/


All Articles