I got Cannot read property 'setContent' of null, when i want to using setContent function. Intended for set value in text editor generated by Tinymce library. Is am wrong to implemented it?Below is my snippet code:
<textarea name="content"></textarea>
<script src="assets/tinymce/tinymce.min.js"></script>
<script>
tinymce.init({
selector:'textarea'
});
tinymce.activeEditor.setContent('custom');
</script>
Does anyone knows about this problem?
Thanks! any effort would be appreciated
You have to wait until the editor is initialized:
tinymce.init({
selector:'textarea',
init_instance_callback : function(editor) {
editor.setContent('custom');
}
});
Real late to the party, but tinyMCE.init also has setup configuration option which allows to add any event handlers to the specific editor being initialised:
tinymce.init({
setup: editor => {
editor.on('init', () => {
editor.setContent('custom');
});
}
});
There is other turn around for your solution:
Call setContent within $( window ).load(function(){}) but you have initialize jquery first.
Modified code will look like below:
<textarea name="content"></textarea>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="assets/tinymce/tinymce.min.js"></script>
<script>
tinymce.init({
selector:'textarea'
});
$( window ).load(function(){
tinymce.activeEditor.setContent('custom');
});
</script>
Related
I have the following code in my cshtml file.
<div style="display:none">
<div id="EditFancy" class="fancybox-infobar">
//Some not relevant input fields.
</div>
</div>
I'm trying to activate/show that fancybox from a javascript which is included at the top of the cshtml file.
However I'm able to activate/show it from a link within the same cshtml file. With the following code:
asd
<script type="text/javascript">
$("#btnForm").fancybox();
</script>
Help will be greatly appreciated.
You could create your own click handler using event-delegation that opens fancybox, for example:
$( "body" ).on( "click", "btnForm", function() {
$.fancybox.open({ src: $(this).attr('href'), type : 'inline' });
});
function viewproperty(){
$.fancybox.open({
src : '#propertyInfo'
});
}
This code is for the latest version of facncybox.
If you use jquery try to wrap the code with $(document).ready() function or use window.onload() javascript function
Used jQuery.fancybox.open(jQuery('#btnForm')); to open the fancybox from the javascript.
I have the jquery script that I am attempting to run.
It is to download into excel file, data from a html table.
http://www.jqueryscript.net/table/Export-Html-Table-To-Excel-Spreadsheet-using-jQuery-table2excel.html
When I try and run the button, it brings up an error stating within this call script:
<script>
$(".dataTable_wrapper button").click(function(){
$("#table2excel").table2excel({
// exclude CSS class
exclude: ".noExl",
name: "Excel Document Name"
});
});
</script>
The error happens on the 2nd line:
"Uncaught type error: $(....) table2excel is not a function"
You may be importing the libraries in the wrong order. Try importing jquery before you import any jquery plugin.
Are you linkiing the js plugin properly? before de exetucion of the code?
try wrapping the function like this:
<script>
$(function(){
$(".dataTable_wrapper button").click(function(){
$("#table2excel").table2excel({
// exclude CSS class
exclude: ".noExl",
name: "Excel Document Name"
});
});
});
</script>
It was pretty simple after all that. I had my script with:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="src/jquery.table2excel.js"></script>
When I changed the location to an actual URL ie:
<script src="myawesomesite.co.uk/wp-content/classes/assets/js/jquery.table2excel.js"></script>
Thanks for you support!
OK so I have a WordPress site. It uses quite a few jQuery scripts and jQuery is loaded in the pages' headers. I have a small block of code that should simple add a class to image links. I have placed this at the bottom of the document, just before the </body> tag.
<script type="text/javascript">
$.noConflict();
$(document).ready(function () {
$('a[href*=".png"], a[href*=".gif"], a[href*=".jpg"]').addClass('zoom');
});
</script>
The script does not work and Firebug is giving me a $ is undefined error. I have checked various similar other question and the answers do not seem to help.
The source page is here: http://sergedenimes.com/2013/01/bruno-bisang-30-years-of-polaroids/
I'm sure it is another plugin causing a conflict but I would appreciate any guidance on how to solve this.
Edit: Wow thanks for the very rapid response. Seems it was an earlier plugin rendering $ undefined. Replacing with jQuery has solved.
You already did jQuery.noConflict(); earlier in your code thereby making $ undefined.
Look at line 79 of your source code.
$.noConflict(); makes the $ symbol go back to it's previous definition before jQuery was loaded. If there were no other libraries using that symbol, then it goes back to undefined. That is its purpose.
If you're going to use that and not define any other symbol as a shortcut for jQuery, then you must use jQuery as the symbol for jQuery functions instead of $.
Do this instead:
<script type="text/javascript">
$.noConflict();
jQuery(document).ready(function () {
jQuery('a[href*=".png"], a[href*=".gif"], a[href*=".jpg"]').addClass('zoom');
});
</script>
or, if you're only trying to use $ inside the .ready() handler, then you can assign it using a feature of .ready() like this:
<script type="text/javascript">
$.noConflict();
jQuery(document).ready(function ($) {
$('a[href*=".png"], a[href*=".gif"], a[href*=".jpg"]').addClass('zoom');
});
</script>
or if you have code that isn't just in the .ready() handler that wants to use $, you can redefine $ in a closure which lets other libraries use $ in their own code, but you can use it for jQuery in your jQuery code inside the closure:
<script type="text/javascript">
$.noConflict();
(function($) {
$(document).ready(function () {
$('a[href*=".png"], a[href*=".gif"], a[href*=".jpg"]').addClass('zoom');
});
$.each(whatever...)
})(jQuery);
</script>
or, you can define a new shortcut symbol for jQuery:
<script type="text/javascript">
var $$ = $.noConflict();
$$(document).ready(function () {
$$('a[href*=".png"], a[href*=".gif"], a[href*=".jpg"]').addClass('zoom');
});
</script>
Try:
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function($) {
$('a[href*=".png"], a[href*=".gif"], a[href*=".jpg"]').addClass('zoom');
});
</script>
I want a tooltip to show when I rollover on particular links. It's not working. The commented out alert is working, so event is not the issue. This is my javascript code:
$(window).load( function() {
$("a").each(function() {
if(this.text==" View image") {
$(this).mouseover(function() {
// alert("blabla");
$(this).tooltip();
});
}
});
});
on my html file the includes are:
<script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" language="javascript" src="jquery.tooltip.min.js"></script>
<script type="text/javascript" language="javascript" src="mainscript.js"></script>
I'd appreciate some help.
UPDATE: removing mouseover doesn't help
Remove the mouseover function. The plugin doesn't require you to add a custom mouseover function. It's done from the plugin for you.
if(this.text==" View image") {
$(this).tooltip();
}
Hope this helps ^^
Change the main jQuery function to $(document).ready(function(){});
This will probably work now~
Try this:
$("a").each(function() {
if(this.innerHTML == " View image") {
$(this).tooltip();
}
}
Also, there's a space before the View in "View image". I'm not sure if that's intentional or not.
I used jQuery tipsy on my recent projects. Quite easy to understand and integrate.
i'm trying this code:
<script type="text/javascript">
$('#ooo').click( function() {
alert("jadner");
});
<script>
prueba
I expected it shows the alert when i click on "prueba", but it doesn't show anything..
Regards
Javi
You need to bind the event only after the DOM finishes loading. Wrap your code inside $(document).load() event like this:
<script type="text/javascript">
$(document).ready(function() {
$('#ooo').click(function() {
alert("jadner");
});
});
</script>
1 - Make sure jQuery has been included.
2 - Make sure your click handler is in a $(document).ready(function() {...}); block.
See:
http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
You have to either reverse the order of the tags, i.e. put the script after the link:
prueba
<script type="text/javascript">...</script>
or wrap the code in a $(document).ready() callback:
$(document).ready(function(){
$('#ooo').click( function() {
alert("jadner");
});
});
The problem: When your JS is executed, it tries to find the element with ID ooo which does not exist yet. Parsing is always from top to bottom. So the script gets executed before the link element is created.
Add return false; below the alert. and like Nanne says, make sure you've got jQuery loaded properly
should be </script> not <script>
use document.ready()
<script type="text/javascript">
$(document).ready(function(){
$('#ooo').click( function() {
alert("jadner");
});
});
</script>
prueba
Try the following code.
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script language="javascript">
$(function()
{
$('#ooo').click( function()
{
alert("jadner");
});
});
</script>
prueba