javascript - jQuery color picker change color on click -
i have jquery color picker inputs want have 1 main input parent other children inputs , want parent input change children inputs value , background color when click button. created function change value of children inputs when there parrent input value set can't figure out how change children input background color same color parent input.
i know have errors becouse when click on button have error message
cannot read property 'target' of undefined
js
function mainbackgroundcolorchange(event) { $(".background-color-features").css({ "background-color": $(event.target).css('background-color'), "color": $(event.target).css('color') }); } // dla tła $('#background-color-main-button').on('click', function () { $('.background-color-features').val($('#background-color-main').val()); mainbackgroundcolorchange(); }); $('.show-hide-color-section-background').on('click', function () { if ($('.color-section-background').is(":visible")) { $('.color-section-background').hide("slide"); $('.show-hide-color-section-background').text('pokaż więcej'); } else { $('.color-section-background').show("slide"); $('.show-hide-color-section-background').text('ukryj'); } });
html/blade.php
<div class="row main-header"> <div class="col-sm-9"> <a href="#" class="page-header" style="color:black">kolory tła głównych elementów</a> </div> </div> <br> <div class="form-group"> <label for="background_color_for_all" class="col-sm-2 control-label">ustaw kolor tła dla wszystkich głównych elementów</label> <div class="col-sm-6 color-pick"> {{form::text('background_color_for_all', null, array('id' => 'background-color-main', 'class' => 'form-control bpm-colorpicker'))}} </div> </div> <div class="color-section-background" style="display: none"> <div class="form-group"> <label for="background_color_subpage_header" class="col-sm-2 control-label">kolor tła w nagłówkach podstron</label> <div class="col-sm-6 color-pick"> {{form::text('background_color_subpage_header', null, array( 'class' => 'form-control bpm-colorpicker background-color-features'))}} </div> </div> <div class="form-group"> <label for="background_color_objects" class="col-sm-2 control-label">kolor tła obiektów (np. listy ofert, wyszukiwarki ofert, nawigacji stron)</label> <div class="col-sm-6"> {{form::text('background_color_objects', null, array('class' => 'form-control bpm-colorpicker background-color-features'))}} </div> </div> <div class="form-group"> <label for="background_color_header" class="col-sm-2 control-label">kolor tła nagłówka</label> <div class="col-sm-6"> {{form::text('background_color_header', null, array( 'class' => 'form-control bpm-colorpicker background-color-features'))}} </div> </div> <div class="form-group"> <label for="background_color_menu_footer" class="col-sm-2 control-label">kolor tła dolnego menu</label> <div class="col-sm-6 color-pick"> {{form::text('background_color_menu_footer', null, array( 'class' => 'form-control bpm-colorpicker background-color-features'))}} </div> </div> <div class="form-group"> <label for="background_color_footer" class="col-sm-2 control-label">kolor tła stopki</label> <div class="col-sm-6"> {{form::text('background_color_footer', null, array( 'class' => 'form-control bpm-colorpicker background-color-features'))}} </div> </div> </div> <div class="form-group"> <span class="col-sm-2"></span> <div class="col-sm-6"> <button type="button" id="background-color-main-button" class="btn btn-seccondary">ustaw dla wszystkich </button> </div> </div> <div class="form-group"> <span class="col-sm-2"></span> <div class="col-sm-6"> <button type="button" class="btn btn-seccondary show-hide-color-section-background"> pokaż więcej </button> </div> </div>
get rid of templating code or paste rendered result is. first problem.
function mainbackgroundcolorchange(event) { $(".background-color-features").css({ "background-color": $(event.target).css('background-color'), "color": $(event.target).css('color') });
}
the target being elements class .background-color-features
, don't exist until template code has run, why getting cannot read property 'target' of undefined
, templating code rendering properly? lets see result.
here fiddle fork from. https://jsfiddle.net/7hjkuzjt/
Comments
Post a Comment