-3

How can I change the CSS attribute? In my case font-size but not last but selected

$("#size").change(function() {
    $("div[id^=new-text]:last").css("font-size", $(this).val() + "px");
});

jsfiddle

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
ArturDvorak
  • 51
  • 1
  • 1
  • 7

1 Answers1

0

Keep track of the selected element. Put a click handler to set a global var to the $(this) - where $(this) is the clicked element.

var selectedText = null;
$('.image').on('click','.new-text', function(){
    selectedText = $(this);
});

$("#size").change(function() {
        selectedText.css("font-size", $(this).val() + "px");
});

http://jsfiddle.net/daveSalomon/a7qyd0na/14/

Dave Salomon
  • 3,287
  • 1
  • 17
  • 29
  • thank can you look on my other problem with draggable http://stackoverflow.com/questions/33147401/selected-added-div-be-draggable?noredirect=1#comment54109017_33147401 – ArturDvorak Oct 16 '15 at 11:34