سؤال

for example:

i click a button. And a div is changeing someting

$('#change').click(function(){ //the button
  $('#myframe').contents().find('#makeit').css("do Someting") //the div in a frame
});

So far i've understand.

I need to know, how can i execute an execCommand (maybe like 'bold') instead of a .css() methode?

هل كانت مفيدة؟

المحلول

I found the answer here.

In my case (jQuery). It looks like

$('#change').click(function(){
   document.getElementById("myframe").contentWindow.document.execCommand('bold', false, null);
});

نصائح أخرى

You want to target execCommand() on an element with id "makeit"?

I'm afraid that's not possible, since it's document.execCommand(String commandName, Bool showUI, Variant value) which executes the command based on the selection / caret focus.

Read eg. https://developer.mozilla.org/en-US/docs/Rich-Text_Editing_in_Mozilla for details.

I forgot to mention the div is contendeditable="true". i want to change the content in the div(id="makeit"). which is in a iframe

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top