css - Jquery and hex colors? -


i can't set color if retrieve hex code color html text. works fine if set color manually.

html

<div class="main-wrapper">    <div class="html-element-color">#ccff00</div>    <div class="wrapper">hello</div> </div> <div class="main-wrapper">    <div class="html-element-color">#cccccc</div>    <div class="wrapper">hello</div> </div> <div class="main-wrapper">    <div class="html-element-color">#f1f1f1</div>    <div class="wrapper">hello</div> </div> 

this code works fine

$( ".html-element-color" ).each(function( index ) {    var bgcolorwrapper = "#ccff00";     $(this).parent().find("div.wrapper").css( "background-color", bgcolorwrapper ) ;  }) 

;

here code doesn't work:

$( ".html-element-color" ).each(function( index ) {    var bgcolorwrapper = $('.html-element-color').text();     $(this).parent().find("div.wrapper").css( "background-color", bgcolorwrapper ) ;  }); 

bg-color invalid variable name. variable names cannot contain dashes. try instead.

$( ".html-element-color" ).each(function( index ) {    var bgcolor = $('.html-element-color').text();     $(this).parent().find("div.wrapper").css( "background-color", bgcolor ) ;  }); 

also, want set color same element, intention unclear post. maybe actually want:

$( ".html-element-color" ).each(function( index ) {    var bgcolor = $(this).text();     $(this).parent().find("div.wrapper").css( "background-color", bgcolor ) ;  }); 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -