0

i get an error in chrome:

Uncaught TypeError: Object s1A has no method 'applyToSelection'

in Firefox(firebug) i get this:

TypeError: val.applyToSelection is not a function

i use the rangy-core and the rangy-cssclassappliere

my Code:

<script type="text/javascript"> 
    window.onload = function() {    
    rangy.init();
      s1A = rangy.createCssClassApplier("css_1", true); 
    };

   //this is the Problem.
   function dosome (el) {
      var val = el.value;
      val.applyToSelection();
   }
</script>

<body>
  <button value="s1A" onclick="dosome(this);">test</button>
</body>

if id do this:

<script type="text/javascript"> 
    window.onload = function() {    
    rangy.init();
      s1A = rangy.createCssClassApplier("css_1", true); 
    };
   function s1() {
      s1A.applyToSelection();
   }
</script>

<body>
  <button onclick="s1();">test</button>
</body>

it works fine. But i need it for an option field and i want to get the value

kuki
  • 79
  • 2
  • 9

1 Answers1

0

I suggest storing appliers in an object where each property name corresponds to an input value:

window.onload = function() {
    var appliers = {};
    rangy.init();
    appliers.s1A = rangy.createCssClassApplier("css_1", true); 
};

function dosome(el) {
    var val = el.value;
    appliers[val].applyToSelection();
}
Tim Down
  • 318,141
  • 75
  • 454
  • 536
  • i'm a beginner in JS and i don't understand your answer but i found an other one [here](http://stackoverflow.com/questions/5809310/jquery-how-do-i-apply-css-to-selected-text). thank you TIM you are an institution – kuki Dec 04 '12 at 18:48