Q1.
I have a total of 7 divs (class name: scale-up-center0 ~ 7), I want to represent numbers 1 through 7 using a javascript variable.
I tried the for statement, but it did not work.
I want scale-up-center7 to change color when scale-up-center0-6 is clicked.
How do I use a javascript variable for a css class name?
not working code
$(document).ready(function() {
for(var i=0; i<7; i++) {
$(".scale-up-center-<%=i%>").click(function() {
var color = $(".scale-up-center-<%=i%>).css("background-color");
$(".scale-up-center7").css("background-color", color);
$("#post_color").val(color);
}
})
})
Q2.
I imported the css property (background-color) through jquery and stored it in the color column.
And displays the color through the input of the form. However, it is expressed in the form of rgb (255,0,0).
I have a color column in the DB, but it is a string type, and rgb () does not.
I want to import the color name rather than rgb. (ex) return "red", instead of rgb (255,0,0)
_form.html.erb
<div class="field">
<%= form.label :color %>
<%= form.text_area :color, id: 'post_color' %>
</div>