Accessing a class name that is stored in the Jquery variable
There are three pictures on the site.
<img src="images/kep1.jpg" class="kep1">
<img src="images/kep2.jpg" class="kep2">
<img src="images/kep4.jpg" class="kep4">
Click function to magnify one page at a time in the middle of the page page, but I'll store the necessary data in a variable.
var pos;
var t;
var h;
var pic;
$("img").click(function(){
pos = $(this).css("position");
pic = $(this).attr("class");
t = $(this).css("top");
h = $(this).css("height");
$(".szurkeDiv").show();
$(this).animate(
{
"position" : "fixed",
"top" : "50%",
"left" : "50%",
"margin-top" : "-300px",
"margin-left" : "-400px",
"width" : "800px",
"height" : "600px"
}, 1000, function(){}
);
});
Then I want you to click on the image in the middle of the page to animate it back to its original location. I would like to access the PIC variable but not succeed.
$(pic).animate(
{
"position" : pos,
"width" : "150px",
"margin-top" : "0px",
"margin-left" : "0px",
"left" : "5px",
"height" : h,
"top" : t
}, 1000, function(){}
);
How can I do this well, refer to the PIC variable?
Thanks for the help!!
jquery html css
add a comment |
There are three pictures on the site.
<img src="images/kep1.jpg" class="kep1">
<img src="images/kep2.jpg" class="kep2">
<img src="images/kep4.jpg" class="kep4">
Click function to magnify one page at a time in the middle of the page page, but I'll store the necessary data in a variable.
var pos;
var t;
var h;
var pic;
$("img").click(function(){
pos = $(this).css("position");
pic = $(this).attr("class");
t = $(this).css("top");
h = $(this).css("height");
$(".szurkeDiv").show();
$(this).animate(
{
"position" : "fixed",
"top" : "50%",
"left" : "50%",
"margin-top" : "-300px",
"margin-left" : "-400px",
"width" : "800px",
"height" : "600px"
}, 1000, function(){}
);
});
Then I want you to click on the image in the middle of the page to animate it back to its original location. I would like to access the PIC variable but not succeed.
$(pic).animate(
{
"position" : pos,
"width" : "150px",
"margin-top" : "0px",
"margin-left" : "0px",
"left" : "5px",
"height" : h,
"top" : t
}, 1000, function(){}
);
How can I do this well, refer to the PIC variable?
Thanks for the help!!
jquery html css
Possible duplicate of jquery select elements by class using name from variable
– Heretic Monkey
Nov 12 '18 at 17:11
jQuery is not a language, it's a library for JavaScript. It doesn't do any magic, it's written in JavaScript code. You should learn the basics of JavaScript before trying to learn how to use any third-party library. I'm not trying to sound judgmental here, just save yourself some trouble and sit through a proper lesson.
– Jacque Goupil
Nov 12 '18 at 17:13
I'm just learning this. This was the home lesson! :-)
– PengeDroid
Nov 12 '18 at 17:40
add a comment |
There are three pictures on the site.
<img src="images/kep1.jpg" class="kep1">
<img src="images/kep2.jpg" class="kep2">
<img src="images/kep4.jpg" class="kep4">
Click function to magnify one page at a time in the middle of the page page, but I'll store the necessary data in a variable.
var pos;
var t;
var h;
var pic;
$("img").click(function(){
pos = $(this).css("position");
pic = $(this).attr("class");
t = $(this).css("top");
h = $(this).css("height");
$(".szurkeDiv").show();
$(this).animate(
{
"position" : "fixed",
"top" : "50%",
"left" : "50%",
"margin-top" : "-300px",
"margin-left" : "-400px",
"width" : "800px",
"height" : "600px"
}, 1000, function(){}
);
});
Then I want you to click on the image in the middle of the page to animate it back to its original location. I would like to access the PIC variable but not succeed.
$(pic).animate(
{
"position" : pos,
"width" : "150px",
"margin-top" : "0px",
"margin-left" : "0px",
"left" : "5px",
"height" : h,
"top" : t
}, 1000, function(){}
);
How can I do this well, refer to the PIC variable?
Thanks for the help!!
jquery html css
There are three pictures on the site.
<img src="images/kep1.jpg" class="kep1">
<img src="images/kep2.jpg" class="kep2">
<img src="images/kep4.jpg" class="kep4">
Click function to magnify one page at a time in the middle of the page page, but I'll store the necessary data in a variable.
var pos;
var t;
var h;
var pic;
$("img").click(function(){
pos = $(this).css("position");
pic = $(this).attr("class");
t = $(this).css("top");
h = $(this).css("height");
$(".szurkeDiv").show();
$(this).animate(
{
"position" : "fixed",
"top" : "50%",
"left" : "50%",
"margin-top" : "-300px",
"margin-left" : "-400px",
"width" : "800px",
"height" : "600px"
}, 1000, function(){}
);
});
Then I want you to click on the image in the middle of the page to animate it back to its original location. I would like to access the PIC variable but not succeed.
$(pic).animate(
{
"position" : pos,
"width" : "150px",
"margin-top" : "0px",
"margin-left" : "0px",
"left" : "5px",
"height" : h,
"top" : t
}, 1000, function(){}
);
How can I do this well, refer to the PIC variable?
Thanks for the help!!
jquery html css
jquery html css
edited Nov 12 '18 at 16:58
asked Nov 12 '18 at 16:52
PengeDroid
135
135
Possible duplicate of jquery select elements by class using name from variable
– Heretic Monkey
Nov 12 '18 at 17:11
jQuery is not a language, it's a library for JavaScript. It doesn't do any magic, it's written in JavaScript code. You should learn the basics of JavaScript before trying to learn how to use any third-party library. I'm not trying to sound judgmental here, just save yourself some trouble and sit through a proper lesson.
– Jacque Goupil
Nov 12 '18 at 17:13
I'm just learning this. This was the home lesson! :-)
– PengeDroid
Nov 12 '18 at 17:40
add a comment |
Possible duplicate of jquery select elements by class using name from variable
– Heretic Monkey
Nov 12 '18 at 17:11
jQuery is not a language, it's a library for JavaScript. It doesn't do any magic, it's written in JavaScript code. You should learn the basics of JavaScript before trying to learn how to use any third-party library. I'm not trying to sound judgmental here, just save yourself some trouble and sit through a proper lesson.
– Jacque Goupil
Nov 12 '18 at 17:13
I'm just learning this. This was the home lesson! :-)
– PengeDroid
Nov 12 '18 at 17:40
Possible duplicate of jquery select elements by class using name from variable
– Heretic Monkey
Nov 12 '18 at 17:11
Possible duplicate of jquery select elements by class using name from variable
– Heretic Monkey
Nov 12 '18 at 17:11
jQuery is not a language, it's a library for JavaScript. It doesn't do any magic, it's written in JavaScript code. You should learn the basics of JavaScript before trying to learn how to use any third-party library. I'm not trying to sound judgmental here, just save yourself some trouble and sit through a proper lesson.
– Jacque Goupil
Nov 12 '18 at 17:13
jQuery is not a language, it's a library for JavaScript. It doesn't do any magic, it's written in JavaScript code. You should learn the basics of JavaScript before trying to learn how to use any third-party library. I'm not trying to sound judgmental here, just save yourself some trouble and sit through a proper lesson.
– Jacque Goupil
Nov 12 '18 at 17:13
I'm just learning this. This was the home lesson! :-)
– PengeDroid
Nov 12 '18 at 17:40
I'm just learning this. This was the home lesson! :-)
– PengeDroid
Nov 12 '18 at 17:40
add a comment |
2 Answers
2
active
oldest
votes
try it with $('.' + pic) instead of $(pic).
See https://jsfiddle.net/g15v3c4z/
var pic = $('p').attr("class");
$('.' + pic).html('world!');
Thanks!!! :-)))
– PengeDroid
Nov 12 '18 at 17:44
add a comment |
Use plain CSS for the animation:
var img = $("img")
img.on("click", function(){
$(this).toggleClass("zoom");
})
img {
transition: all 0.5s ease;
}
.zoom {
transform:scale(2);
transform-origin: 0 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
</div>
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%2f53266706%2faccessing-a-class-name-that-is-stored-in-the-jquery-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
try it with $('.' + pic) instead of $(pic).
See https://jsfiddle.net/g15v3c4z/
var pic = $('p').attr("class");
$('.' + pic).html('world!');
Thanks!!! :-)))
– PengeDroid
Nov 12 '18 at 17:44
add a comment |
try it with $('.' + pic) instead of $(pic).
See https://jsfiddle.net/g15v3c4z/
var pic = $('p').attr("class");
$('.' + pic).html('world!');
Thanks!!! :-)))
– PengeDroid
Nov 12 '18 at 17:44
add a comment |
try it with $('.' + pic) instead of $(pic).
See https://jsfiddle.net/g15v3c4z/
var pic = $('p').attr("class");
$('.' + pic).html('world!');
try it with $('.' + pic) instead of $(pic).
See https://jsfiddle.net/g15v3c4z/
var pic = $('p').attr("class");
$('.' + pic).html('world!');
answered Nov 12 '18 at 17:02
Andreas
443
443
Thanks!!! :-)))
– PengeDroid
Nov 12 '18 at 17:44
add a comment |
Thanks!!! :-)))
– PengeDroid
Nov 12 '18 at 17:44
Thanks!!! :-)))
– PengeDroid
Nov 12 '18 at 17:44
Thanks!!! :-)))
– PengeDroid
Nov 12 '18 at 17:44
add a comment |
Use plain CSS for the animation:
var img = $("img")
img.on("click", function(){
$(this).toggleClass("zoom");
})
img {
transition: all 0.5s ease;
}
.zoom {
transform:scale(2);
transform-origin: 0 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
</div>
add a comment |
Use plain CSS for the animation:
var img = $("img")
img.on("click", function(){
$(this).toggleClass("zoom");
})
img {
transition: all 0.5s ease;
}
.zoom {
transform:scale(2);
transform-origin: 0 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
</div>
add a comment |
Use plain CSS for the animation:
var img = $("img")
img.on("click", function(){
$(this).toggleClass("zoom");
})
img {
transition: all 0.5s ease;
}
.zoom {
transform:scale(2);
transform-origin: 0 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
</div>
Use plain CSS for the animation:
var img = $("img")
img.on("click", function(){
$(this).toggleClass("zoom");
})
img {
transition: all 0.5s ease;
}
.zoom {
transform:scale(2);
transform-origin: 0 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
</div>
var img = $("img")
img.on("click", function(){
$(this).toggleClass("zoom");
})
img {
transition: all 0.5s ease;
}
.zoom {
transform:scale(2);
transform-origin: 0 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
</div>
var img = $("img")
img.on("click", function(){
$(this).toggleClass("zoom");
})
img {
transition: all 0.5s ease;
}
.zoom {
transform:scale(2);
transform-origin: 0 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
<img src="https://via.placeholder.com/350" alt="">
</div>
answered Nov 12 '18 at 17:24
Ihsan S
324
324
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53266706%2faccessing-a-class-name-that-is-stored-in-the-jquery-variable%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
Possible duplicate of jquery select elements by class using name from variable
– Heretic Monkey
Nov 12 '18 at 17:11
jQuery is not a language, it's a library for JavaScript. It doesn't do any magic, it's written in JavaScript code. You should learn the basics of JavaScript before trying to learn how to use any third-party library. I'm not trying to sound judgmental here, just save yourself some trouble and sit through a proper lesson.
– Jacque Goupil
Nov 12 '18 at 17:13
I'm just learning this. This was the home lesson! :-)
– PengeDroid
Nov 12 '18 at 17:40