Here is my code:(Jquery)
<script src="./minified/jquery.sceditor.bbcode.min.js"></script>
<script> var loadCSS = function(url, callback){
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = url;
link.id = 'theme-style';
document.getElementsByTagName('head')[0].appendChild(link);
var img = document.createElement('img');
img.onerror = function(){
if(callback) callback(link);
}
img.src = url;
}
$(document).ready(function() {
var initEditor = function() {
$(".new_text").sceditor({
plugins: 'bbcode',
style: "./minified/jquery.sceditor.default.min.css"
});
};
$("#theme").change(function() {
var theme = "./minified/themes/" + $(this).val() + ".min.css";
$(".new_text").sceditor("instance").destroy();
$("link:first").remove();
$("#theme-style").remove();
loadCSS(theme, initEditor);
});
initEditor();
});
</script>
This code is not working after Ajax on change function. My html code is here: Here is ajax response:
<div id="txtHint" style="margin-left: 160px;">
<textarea class="new_text" name="about_builder" id="about_builder" style="height:200px;width:600px;">
<?php echo $row_ab['about_builder']; ?>
</textarea></div>
problem is after ajax that text area plugin was not working.
You need to always call .sceditor
when you add new html using ajax. You also should modify the function to call the sceditor
on only the newly added element.
var initEditor = function(context) { //Add a context parameter to search only from this context
$(".new_text",context).sceditor({
plugins: 'bbcode',
style: "./minified/jquery.sceditor.default.min.css"
});
};
Your ajax function looks like this:
$.ajax({
//
})
.done(function(data){
yourContainer.html(data); //When you load the html, you need to insert it into the DOM
initEditor(yourContainer);//call the sceditor on the newly added element.
});