Extract img attribute from html
I'm using revolution slider. When the slider changes, I want to grab the "id" attribute of the <img>
tag and use it for further processing.
This is all I have so far:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html();
alert(html);
});
This alerts the following (simplified):
<div class="slotholder">
<img src="aa5.jpg" class="rev-slidebg aSliderImage defaultimg" id="aSliderImage_2_3">
<div class="tp-bgimg defaultimg" style="background-image: url("aa5.jpg");">
</div>
</div>
I specifically need
id="aSliderImage_2_3"
jquery
add a comment |
I'm using revolution slider. When the slider changes, I want to grab the "id" attribute of the <img>
tag and use it for further processing.
This is all I have so far:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html();
alert(html);
});
This alerts the following (simplified):
<div class="slotholder">
<img src="aa5.jpg" class="rev-slidebg aSliderImage defaultimg" id="aSliderImage_2_3">
<div class="tp-bgimg defaultimg" style="background-image: url("aa5.jpg");">
</div>
</div>
I specifically need
id="aSliderImage_2_3"
jquery
add a comment |
I'm using revolution slider. When the slider changes, I want to grab the "id" attribute of the <img>
tag and use it for further processing.
This is all I have so far:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html();
alert(html);
});
This alerts the following (simplified):
<div class="slotholder">
<img src="aa5.jpg" class="rev-slidebg aSliderImage defaultimg" id="aSliderImage_2_3">
<div class="tp-bgimg defaultimg" style="background-image: url("aa5.jpg");">
</div>
</div>
I specifically need
id="aSliderImage_2_3"
jquery
I'm using revolution slider. When the slider changes, I want to grab the "id" attribute of the <img>
tag and use it for further processing.
This is all I have so far:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html();
alert(html);
});
This alerts the following (simplified):
<div class="slotholder">
<img src="aa5.jpg" class="rev-slidebg aSliderImage defaultimg" id="aSliderImage_2_3">
<div class="tp-bgimg defaultimg" style="background-image: url("aa5.jpg");">
</div>
</div>
I specifically need
id="aSliderImage_2_3"
jquery
jquery
asked Nov 16 '18 at 4:42
user460114user460114
80222144
80222144
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I think data.currentslide.html()
is returning string. So wrap it with $(...)
will convert it into object and you can perform find
on it.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img");
alert(img.attr("id"));
});
Edit 1
Updated find
selector. Hopefully this could work for your complicated object.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img.aSliderImage:first");
alert(img.attr("id"));
});
No errors, but it alerts "undefined".
– user460114
Nov 16 '18 at 4:59
I think it returned undefined because the actual html is much more complicated than I used in my original post. I have tried the simplified html and it DOES work. So, I will just play with it until it works with the complicated code.
– user460114
Nov 16 '18 at 5:03
1
$(data.currentslide.html())
will return regularjQuery
object as you perform onDOM
. So you can use anyjquery
selectors
like.class
etc.
– Karan
Nov 16 '18 at 5:08
add a comment |
Just go further into your HTML and find the <img>
, then alert the id
attribute:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html().filter("img");
alert(html.attr("id"));
});
I tried that and I get the error "data.currentslide.html(...).find is not a function"
– user460114
Nov 16 '18 at 4:52
What error do you get?
– Jack Bashford
Nov 16 '18 at 4:52
Changed it now, any better @user460114
– Jack Bashford
Nov 16 '18 at 4:52
Error: data.currentslide.html(...).filter is not a function
– user460114
Nov 16 '18 at 4:54
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%2f53331563%2fextract-img-attribute-from-html%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
I think data.currentslide.html()
is returning string. So wrap it with $(...)
will convert it into object and you can perform find
on it.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img");
alert(img.attr("id"));
});
Edit 1
Updated find
selector. Hopefully this could work for your complicated object.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img.aSliderImage:first");
alert(img.attr("id"));
});
No errors, but it alerts "undefined".
– user460114
Nov 16 '18 at 4:59
I think it returned undefined because the actual html is much more complicated than I used in my original post. I have tried the simplified html and it DOES work. So, I will just play with it until it works with the complicated code.
– user460114
Nov 16 '18 at 5:03
1
$(data.currentslide.html())
will return regularjQuery
object as you perform onDOM
. So you can use anyjquery
selectors
like.class
etc.
– Karan
Nov 16 '18 at 5:08
add a comment |
I think data.currentslide.html()
is returning string. So wrap it with $(...)
will convert it into object and you can perform find
on it.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img");
alert(img.attr("id"));
});
Edit 1
Updated find
selector. Hopefully this could work for your complicated object.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img.aSliderImage:first");
alert(img.attr("id"));
});
No errors, but it alerts "undefined".
– user460114
Nov 16 '18 at 4:59
I think it returned undefined because the actual html is much more complicated than I used in my original post. I have tried the simplified html and it DOES work. So, I will just play with it until it works with the complicated code.
– user460114
Nov 16 '18 at 5:03
1
$(data.currentslide.html())
will return regularjQuery
object as you perform onDOM
. So you can use anyjquery
selectors
like.class
etc.
– Karan
Nov 16 '18 at 5:08
add a comment |
I think data.currentslide.html()
is returning string. So wrap it with $(...)
will convert it into object and you can perform find
on it.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img");
alert(img.attr("id"));
});
Edit 1
Updated find
selector. Hopefully this could work for your complicated object.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img.aSliderImage:first");
alert(img.attr("id"));
});
I think data.currentslide.html()
is returning string. So wrap it with $(...)
will convert it into object and you can perform find
on it.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img");
alert(img.attr("id"));
});
Edit 1
Updated find
selector. Hopefully this could work for your complicated object.
revapi.on('revolution.slide.onafterswap', function(event, data) {
var img = $(data.currentslide.html()).find("img.aSliderImage:first");
alert(img.attr("id"));
});
edited Nov 16 '18 at 5:11
answered Nov 16 '18 at 4:52
KaranKaran
3,4062525
3,4062525
No errors, but it alerts "undefined".
– user460114
Nov 16 '18 at 4:59
I think it returned undefined because the actual html is much more complicated than I used in my original post. I have tried the simplified html and it DOES work. So, I will just play with it until it works with the complicated code.
– user460114
Nov 16 '18 at 5:03
1
$(data.currentslide.html())
will return regularjQuery
object as you perform onDOM
. So you can use anyjquery
selectors
like.class
etc.
– Karan
Nov 16 '18 at 5:08
add a comment |
No errors, but it alerts "undefined".
– user460114
Nov 16 '18 at 4:59
I think it returned undefined because the actual html is much more complicated than I used in my original post. I have tried the simplified html and it DOES work. So, I will just play with it until it works with the complicated code.
– user460114
Nov 16 '18 at 5:03
1
$(data.currentslide.html())
will return regularjQuery
object as you perform onDOM
. So you can use anyjquery
selectors
like.class
etc.
– Karan
Nov 16 '18 at 5:08
No errors, but it alerts "undefined".
– user460114
Nov 16 '18 at 4:59
No errors, but it alerts "undefined".
– user460114
Nov 16 '18 at 4:59
I think it returned undefined because the actual html is much more complicated than I used in my original post. I have tried the simplified html and it DOES work. So, I will just play with it until it works with the complicated code.
– user460114
Nov 16 '18 at 5:03
I think it returned undefined because the actual html is much more complicated than I used in my original post. I have tried the simplified html and it DOES work. So, I will just play with it until it works with the complicated code.
– user460114
Nov 16 '18 at 5:03
1
1
$(data.currentslide.html())
will return regular jQuery
object as you perform on DOM
. So you can use any jquery
selectors
like .class
etc.– Karan
Nov 16 '18 at 5:08
$(data.currentslide.html())
will return regular jQuery
object as you perform on DOM
. So you can use any jquery
selectors
like .class
etc.– Karan
Nov 16 '18 at 5:08
add a comment |
Just go further into your HTML and find the <img>
, then alert the id
attribute:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html().filter("img");
alert(html.attr("id"));
});
I tried that and I get the error "data.currentslide.html(...).find is not a function"
– user460114
Nov 16 '18 at 4:52
What error do you get?
– Jack Bashford
Nov 16 '18 at 4:52
Changed it now, any better @user460114
– Jack Bashford
Nov 16 '18 at 4:52
Error: data.currentslide.html(...).filter is not a function
– user460114
Nov 16 '18 at 4:54
add a comment |
Just go further into your HTML and find the <img>
, then alert the id
attribute:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html().filter("img");
alert(html.attr("id"));
});
I tried that and I get the error "data.currentslide.html(...).find is not a function"
– user460114
Nov 16 '18 at 4:52
What error do you get?
– Jack Bashford
Nov 16 '18 at 4:52
Changed it now, any better @user460114
– Jack Bashford
Nov 16 '18 at 4:52
Error: data.currentslide.html(...).filter is not a function
– user460114
Nov 16 '18 at 4:54
add a comment |
Just go further into your HTML and find the <img>
, then alert the id
attribute:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html().filter("img");
alert(html.attr("id"));
});
Just go further into your HTML and find the <img>
, then alert the id
attribute:
revapi.on('revolution.slide.onafterswap', function(event, data) {
var html = data.currentslide.html().filter("img");
alert(html.attr("id"));
});
edited Nov 16 '18 at 4:52
answered Nov 16 '18 at 4:50
Jack BashfordJack Bashford
12.9k31847
12.9k31847
I tried that and I get the error "data.currentslide.html(...).find is not a function"
– user460114
Nov 16 '18 at 4:52
What error do you get?
– Jack Bashford
Nov 16 '18 at 4:52
Changed it now, any better @user460114
– Jack Bashford
Nov 16 '18 at 4:52
Error: data.currentslide.html(...).filter is not a function
– user460114
Nov 16 '18 at 4:54
add a comment |
I tried that and I get the error "data.currentslide.html(...).find is not a function"
– user460114
Nov 16 '18 at 4:52
What error do you get?
– Jack Bashford
Nov 16 '18 at 4:52
Changed it now, any better @user460114
– Jack Bashford
Nov 16 '18 at 4:52
Error: data.currentslide.html(...).filter is not a function
– user460114
Nov 16 '18 at 4:54
I tried that and I get the error "data.currentslide.html(...).find is not a function"
– user460114
Nov 16 '18 at 4:52
I tried that and I get the error "data.currentslide.html(...).find is not a function"
– user460114
Nov 16 '18 at 4:52
What error do you get?
– Jack Bashford
Nov 16 '18 at 4:52
What error do you get?
– Jack Bashford
Nov 16 '18 at 4:52
Changed it now, any better @user460114
– Jack Bashford
Nov 16 '18 at 4:52
Changed it now, any better @user460114
– Jack Bashford
Nov 16 '18 at 4:52
Error: data.currentslide.html(...).filter is not a function
– user460114
Nov 16 '18 at 4:54
Error: data.currentslide.html(...).filter is not a function
– user460114
Nov 16 '18 at 4:54
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%2f53331563%2fextract-img-attribute-from-html%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