This should do what you ask ... It seems like a good solution for me:
http://jsfiddle.net/CLjZt/2/
jQuery:
$('div[data-entry=item]').click( function() { id = this.id; $('#fs').change( function(){ $("#"+id).css('font-family', $('#fs').val()); }); $('#size').change( function(){ $('#'+id).css('font-size', $('#size').val()+"px"); }); });
HTML:
<form id="myform"> <select id="fs"> <option value="Arial">Arial</option> <option value="Verdana">Verdana</option> <option value="Impact">Impact</option> <option value="Comic Sans MS">Comic Sans MS</option> </select> <select id="size"> <option value="7">7</option> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> </select> </form> <br/> <div data-entry="item" id="name" class="name">dsfdsfsfdsdfdsf</div> <div data-entry="item" id="address" class="address">sdfsdfdsfdsfdsf</div> <div data-entry="item" id="address1" class="address1">sdfsdfdsfdsfdsf</div>
The function adds a click event to the div [data-entry = item] selector, and then writes the identifier of the element that was clicked on the id variable. Then it launches two functions that listen for changes to #fs and #size select elements. If a change is detected, it uses the same selector that you created to make changes to the css properties in the value selected item .
(you can delete this data type and use the same identifier for all three elements, but I was not sure that for some reason you need both a class and an identifier)
Trevasaurusrex
source share