get the context of a created canvas with JQuery
I'm trying to use this methods ( http://jsfiddle.net/erickzanardo/RHZL6/ ) to create a canvas with createElement and then draw on it, but since I'm using JQuery the canvas so created deosn't have a class function getContext("2d"), but it seems to work on the last jsfiddle.
My code is as follow :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
var map_rendered = document.createElement("map");
map_rendered.heigt = 100 ; map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
the error I get is :
TypeError: map_rendered.getContext is not a function
Do you have a way to solve it, or any other method to create a pre-rendered map, my aim is then to display a subsection of this map in a smaller canvas.
Thanks.
javascript html canvas createelement
add a comment |
I'm trying to use this methods ( http://jsfiddle.net/erickzanardo/RHZL6/ ) to create a canvas with createElement and then draw on it, but since I'm using JQuery the canvas so created deosn't have a class function getContext("2d"), but it seems to work on the last jsfiddle.
My code is as follow :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
var map_rendered = document.createElement("map");
map_rendered.heigt = 100 ; map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
the error I get is :
TypeError: map_rendered.getContext is not a function
Do you have a way to solve it, or any other method to create a pre-rendered map, my aim is then to display a subsection of this map in a smaller canvas.
Thanks.
javascript html canvas createelement
4
map_rendered
is a<map>
element. You must use a<canvas>
element if you hope.getContext('2d');
to succeed.
– enhzflep
Dec 28 '18 at 12:27
1
Also this has nothing to do with jQuery.
– Mark Baijens
Dec 28 '18 at 12:29
add a comment |
I'm trying to use this methods ( http://jsfiddle.net/erickzanardo/RHZL6/ ) to create a canvas with createElement and then draw on it, but since I'm using JQuery the canvas so created deosn't have a class function getContext("2d"), but it seems to work on the last jsfiddle.
My code is as follow :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
var map_rendered = document.createElement("map");
map_rendered.heigt = 100 ; map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
the error I get is :
TypeError: map_rendered.getContext is not a function
Do you have a way to solve it, or any other method to create a pre-rendered map, my aim is then to display a subsection of this map in a smaller canvas.
Thanks.
javascript html canvas createelement
I'm trying to use this methods ( http://jsfiddle.net/erickzanardo/RHZL6/ ) to create a canvas with createElement and then draw on it, but since I'm using JQuery the canvas so created deosn't have a class function getContext("2d"), but it seems to work on the last jsfiddle.
My code is as follow :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
var map_rendered = document.createElement("map");
map_rendered.heigt = 100 ; map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
the error I get is :
TypeError: map_rendered.getContext is not a function
Do you have a way to solve it, or any other method to create a pre-rendered map, my aim is then to display a subsection of this map in a smaller canvas.
Thanks.
javascript html canvas createelement
javascript html canvas createelement
edited Dec 28 '18 at 13:09
Kaiido
39.7k45899
39.7k45899
asked Dec 28 '18 at 12:24
fraglothfragloth
42
42
4
map_rendered
is a<map>
element. You must use a<canvas>
element if you hope.getContext('2d');
to succeed.
– enhzflep
Dec 28 '18 at 12:27
1
Also this has nothing to do with jQuery.
– Mark Baijens
Dec 28 '18 at 12:29
add a comment |
4
map_rendered
is a<map>
element. You must use a<canvas>
element if you hope.getContext('2d');
to succeed.
– enhzflep
Dec 28 '18 at 12:27
1
Also this has nothing to do with jQuery.
– Mark Baijens
Dec 28 '18 at 12:29
4
4
map_rendered
is a <map>
element. You must use a <canvas>
element if you hope .getContext('2d');
to succeed.– enhzflep
Dec 28 '18 at 12:27
map_rendered
is a <map>
element. You must use a <canvas>
element if you hope .getContext('2d');
to succeed.– enhzflep
Dec 28 '18 at 12:27
1
1
Also this has nothing to do with jQuery.
– Mark Baijens
Dec 28 '18 at 12:29
Also this has nothing to do with jQuery.
– Mark Baijens
Dec 28 '18 at 12:29
add a comment |
1 Answer
1
active
oldest
votes
change "map" to "canvas", and error will gone
var map_rendered = document.createElement("canvas");
map_rendered.heigt = 100 ;
map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
thank you very much, I thought we could give an arbitrary name in the function createElement.
– fragloth
Dec 28 '18 at 13:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958578%2fget-the-context-of-a-created-canvas-with-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
change "map" to "canvas", and error will gone
var map_rendered = document.createElement("canvas");
map_rendered.heigt = 100 ;
map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
thank you very much, I thought we could give an arbitrary name in the function createElement.
– fragloth
Dec 28 '18 at 13:42
add a comment |
change "map" to "canvas", and error will gone
var map_rendered = document.createElement("canvas");
map_rendered.heigt = 100 ;
map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
thank you very much, I thought we could give an arbitrary name in the function createElement.
– fragloth
Dec 28 '18 at 13:42
add a comment |
change "map" to "canvas", and error will gone
var map_rendered = document.createElement("canvas");
map_rendered.heigt = 100 ;
map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
change "map" to "canvas", and error will gone
var map_rendered = document.createElement("canvas");
map_rendered.heigt = 100 ;
map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
var map_rendered = document.createElement("canvas");
map_rendered.heigt = 100 ;
map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
var map_rendered = document.createElement("canvas");
map_rendered.heigt = 100 ;
map_rendered.width = 100 ;
var map_rendered_ctx = map_rendered.getContext("2d");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
answered Dec 28 '18 at 12:28
Vadim HulevichVadim Hulevich
4867
4867
thank you very much, I thought we could give an arbitrary name in the function createElement.
– fragloth
Dec 28 '18 at 13:42
add a comment |
thank you very much, I thought we could give an arbitrary name in the function createElement.
– fragloth
Dec 28 '18 at 13:42
thank you very much, I thought we could give an arbitrary name in the function createElement.
– fragloth
Dec 28 '18 at 13:42
thank you very much, I thought we could give an arbitrary name in the function createElement.
– fragloth
Dec 28 '18 at 13:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958578%2fget-the-context-of-a-created-canvas-with-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
map_rendered
is a<map>
element. You must use a<canvas>
element if you hope.getContext('2d');
to succeed.– enhzflep
Dec 28 '18 at 12:27
1
Also this has nothing to do with jQuery.
– Mark Baijens
Dec 28 '18 at 12:29