html2canvas Error : Uncaught TypeError: undefined is not a function - html2canvas

I have used the below code to generate the screenshot of a grid in my page. The 'gridBody' in the code below is a DOM object.
html2canvas(gridBody ,{
onrendered:function(canvas){
var img = canvas.toDataURL();
window.open(img);
}
});
But it gives an error:
Uncaught TypeError: undefined is not a function (html2canvas.js:2191)
_html2canvas.Preload (html2canvas.js:2191)
(anonymous function)
line 2191 in html2canvas.js file:
domImages = element.getElementsByTagName('img'), // Fetch images of the present element only
This works absolutely fine when i give 'document.body' instead of 'gridBody'.
Can you please help me out, why is the error coming?
Note: gridBody DOM starts and ends with
<div>
tags. I can share it, but this space doesnt allow to paste the entire DOM here, and i dont see any way to attach a file.

I had this problem, and found that it was due to the selector that was passed in to html2canvas being empty. This resulted in 'element' not being an element.

Related

How to resolve Leaflet TypeError: L.control.selectLayers is not a function

I wish to make a dropdown list to replace the default tool for layer selection.
Using this example included in from the GIT repository, and adjust for jsfiddle, I get the following error:
"<a class='gotoLine' href='#77:31'>77:31</a> TypeError: L.control.selectLayers is not a function"
using L.control.layers works fine, however, not selectLayers.
//var control = L.control.layers(baseMaps, overlayMaps)
var control = L.control.selectLayers(baseMaps, overlayMaps)
control.addTo(map);
The appropriate javascript files all seem to be in place, so.. what is missing here?
Fiddle link:
You added the wrong link of the libraries.
You have to use the raw link instead of the Github link

Unable to add content to Textarea editor on Redactor 2. "Uncaught TypeError: Cannot read property 'code' of undefined"

I have Redactor II (version 1.2.5) which I used to edit content on a database. When the page is loaded I load the content that needs to be edited, and I use the following code to add the content in to the Redactor editor:
$('#eg_description').redactor('code.set', 'My text goes here');
However, when I load the page I get this error:
Uncaught TypeError: Cannot read property 'code' of undefined
I've also tried this:
$('#eg_description').redactor('this.code.set', 'My text goes here');
Which gives the following similar error:
Uncaught TypeError: Cannot read property 'this' of undefined
Not entirely sure why it isn't working, so any help would be appreciated!
Please make sure you first enable Redactor on the same element, i.e. you call
$('#eg_description').redactor(); //you can provide options object here

prevObject returned when selecting an element

So I'm making some elements in my js file as follows:
grocerySpan = $("<span>").addClass("grocery").html(grocery.name).attr('id',"page"+groceriesIdCounter);
My first question is whether it is ok that I am assigning id as i did in the line above (using string concatenating)?
I have different spans made with each their own id, #page0, #page1..., now when I try selecting the a specific span as follows:
var tempGrocerySpan = $("span"+"#page"+groceriesIdCounter+".grocery");
I get a prevObject returned.
now here is a screenshot of my DOM from
chrome debugger
As I read a prevObject means that the selector can't find the current element selected, but as I can see from chrome debugger my selecter and the element selector are the same, or am I overseeing something?
Thanks for the help.

How to use jQuery to search for text that contains a bracket "("?

I'm trying to use jQuery to locate all <a> tags that contain a piece of text in brackets so I can perform some manipulation on them.
However I'm struggling to even find these tags. And I am getting a javascript error:
"Syntax error, unrecognized expression: '(')"
When I try to use the following code:
jQuery("a:contains(' (')").css("text-decoration", "underline");
Presumably because the javascript doesn't like a ( within the contains function. Does anyone know a way around this?
Thanks in advance!
$('a').each(function(index){
if($(this).text().indexOf('(')!=-1){
$(this).css("text-decoration","underline");
}
});
This is not a performant solution but just a hint, iterate over every <a> get their text() and if they contain a ( underline them.
If your ( is not in between HERE() you could check for the href attribute and get it's value and look if in the value it contains (
Please check this
<script>
var sent = "(";
$("a:contains("+sent+")").css("text-decoration", "underline");
</script>

jquery .each produces 'undefined' whenever .data is used on the elements returned

I'm trying to process all select elements with a specific data- attribute set.
I've got the loop working to pick up the element, but whenever I try to find the value of its other data- attributes I get undefined error messages.
Here is the loop:
$('select[data-hm-observed="1"]').each(function(idx, sel) {
alert(sel.getAttribute('data-hm-url'));
alert(sel.data('hmUrl'));
});
In the loop the first alert works, but the second produces:
TypeError: 'undefined' is not a function (evaluating
'sel.data('hmUrl')')
If I use the Safari console I can get the select object, put it in a variable, and interrogate its data- attributes without issue.
It seems that the .each() is having an effect on the sel variable contents - but I can't understand what.
Using JQuery 1.7.1
UPDATE:
Just discovered that if I change the loop so that it explicitly gets the element again, it all works:
$('select[data-hm-observed="1"]').each(function(idx, sel) {
xx = $(sel);
alert(sel.getAttribute('data-hm-url'));
alert(xx.data('hmUrl'));
});
Is this the correct solution?
Can I infer from this that the element passed into the loop by .each hasn't been 'processed' by jquery, and that I have to pull it myself via $(...) so that jquery does its stuff to it - this doesn't feel right - but its working.
sel is a DOM Object here, not equipped with the abilities of a jQuery Object. First, you should turn this DOM Object into a jQuery Object like this:
alert( $(sel).data('hmUrl') );
Alternatively, you can also use $(this).data('hmUrl'), because this will refer to sel (the current DOM element in the iteration).
See also .each() 2nd Example