Extract img attribute from html












-1















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(&quot;aa5.jpg&quot;);">
</div>
</div>


I specifically need



id="aSliderImage_2_3"









share|improve this question



























    -1















    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(&quot;aa5.jpg&quot;);">
    </div>
    </div>


    I specifically need



    id="aSliderImage_2_3"









    share|improve this question

























      -1












      -1








      -1








      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(&quot;aa5.jpg&quot;);">
      </div>
      </div>


      I specifically need



      id="aSliderImage_2_3"









      share|improve this question














      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(&quot;aa5.jpg&quot;);">
      </div>
      </div>


      I specifically need



      id="aSliderImage_2_3"






      jquery






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 4:42









      user460114user460114

      80222144




      80222144
























          2 Answers
          2






          active

          oldest

          votes


















          0














          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"));
          });





          share|improve this answer


























          • 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 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



















          0














          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"));
          });





          share|improve this answer


























          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          0














          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"));
          });





          share|improve this answer


























          • 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 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
















          0














          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"));
          });





          share|improve this answer


























          • 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 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














          0












          0








          0







          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"));
          });





          share|improve this answer















          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"));
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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 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



















          • 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 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

















          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













          0














          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"));
          });





          share|improve this answer


























          • 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
















          0














          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"));
          });





          share|improve this answer


























          • 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














          0












          0








          0







          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"));
          });





          share|improve this answer















          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"));
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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



















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python