Take attribute value from where style display is not none











up vote
1
down vote

favorite












I have few divs:



<div clas="modal-body step step-1" data-step="1" style="display: block;"></div>
<div clas="modal-body step step-2" data-step="2" style="display: none;"></div>
<div clas="modal-body step step-3" data-step="3" style="display: none;"></div>


I would like to get the value of attribute "data-step" where style: display is not none.



Is it possible with JavaScript or JQuery?










share|improve this question




















  • 3




    Well, since JQuery is JavaScript, there's nothing that one can do that the other can't and, of course, this is possible. The question really is, what have you tried? Have you read about how to query for elements based on their attributes? Have you read about data-* attributes and how to access them via the DOM?
    – Scott Marcus
    Nov 7 at 18:06








  • 1




    Well, I am ashamed, because first I wrote question, then I think. It can by done by $(".step[display!='none']").attr("data-step")
    – goskan
    Nov 7 at 18:10








  • 1




    $('.step:visible').attr('data-step');
    – Adam Łożyński
    Nov 7 at 18:12















up vote
1
down vote

favorite












I have few divs:



<div clas="modal-body step step-1" data-step="1" style="display: block;"></div>
<div clas="modal-body step step-2" data-step="2" style="display: none;"></div>
<div clas="modal-body step step-3" data-step="3" style="display: none;"></div>


I would like to get the value of attribute "data-step" where style: display is not none.



Is it possible with JavaScript or JQuery?










share|improve this question




















  • 3




    Well, since JQuery is JavaScript, there's nothing that one can do that the other can't and, of course, this is possible. The question really is, what have you tried? Have you read about how to query for elements based on their attributes? Have you read about data-* attributes and how to access them via the DOM?
    – Scott Marcus
    Nov 7 at 18:06








  • 1




    Well, I am ashamed, because first I wrote question, then I think. It can by done by $(".step[display!='none']").attr("data-step")
    – goskan
    Nov 7 at 18:10








  • 1




    $('.step:visible').attr('data-step');
    – Adam Łożyński
    Nov 7 at 18:12













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have few divs:



<div clas="modal-body step step-1" data-step="1" style="display: block;"></div>
<div clas="modal-body step step-2" data-step="2" style="display: none;"></div>
<div clas="modal-body step step-3" data-step="3" style="display: none;"></div>


I would like to get the value of attribute "data-step" where style: display is not none.



Is it possible with JavaScript or JQuery?










share|improve this question















I have few divs:



<div clas="modal-body step step-1" data-step="1" style="display: block;"></div>
<div clas="modal-body step step-2" data-step="2" style="display: none;"></div>
<div clas="modal-body step step-3" data-step="3" style="display: none;"></div>


I would like to get the value of attribute "data-step" where style: display is not none.



Is it possible with JavaScript or JQuery?







javascript jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 18:09









Scott Marcus

38k51936




38k51936










asked Nov 7 at 18:04









goskan

277




277








  • 3




    Well, since JQuery is JavaScript, there's nothing that one can do that the other can't and, of course, this is possible. The question really is, what have you tried? Have you read about how to query for elements based on their attributes? Have you read about data-* attributes and how to access them via the DOM?
    – Scott Marcus
    Nov 7 at 18:06








  • 1




    Well, I am ashamed, because first I wrote question, then I think. It can by done by $(".step[display!='none']").attr("data-step")
    – goskan
    Nov 7 at 18:10








  • 1




    $('.step:visible').attr('data-step');
    – Adam Łożyński
    Nov 7 at 18:12














  • 3




    Well, since JQuery is JavaScript, there's nothing that one can do that the other can't and, of course, this is possible. The question really is, what have you tried? Have you read about how to query for elements based on their attributes? Have you read about data-* attributes and how to access them via the DOM?
    – Scott Marcus
    Nov 7 at 18:06








  • 1




    Well, I am ashamed, because first I wrote question, then I think. It can by done by $(".step[display!='none']").attr("data-step")
    – goskan
    Nov 7 at 18:10








  • 1




    $('.step:visible').attr('data-step');
    – Adam Łożyński
    Nov 7 at 18:12








3




3




Well, since JQuery is JavaScript, there's nothing that one can do that the other can't and, of course, this is possible. The question really is, what have you tried? Have you read about how to query for elements based on their attributes? Have you read about data-* attributes and how to access them via the DOM?
– Scott Marcus
Nov 7 at 18:06






Well, since JQuery is JavaScript, there's nothing that one can do that the other can't and, of course, this is possible. The question really is, what have you tried? Have you read about how to query for elements based on their attributes? Have you read about data-* attributes and how to access them via the DOM?
– Scott Marcus
Nov 7 at 18:06






1




1




Well, I am ashamed, because first I wrote question, then I think. It can by done by $(".step[display!='none']").attr("data-step")
– goskan
Nov 7 at 18:10






Well, I am ashamed, because first I wrote question, then I think. It can by done by $(".step[display!='none']").attr("data-step")
– goskan
Nov 7 at 18:10






1




1




$('.step:visible').attr('data-step');
– Adam Łożyński
Nov 7 at 18:12




$('.step:visible').attr('data-step');
– Adam Łożyński
Nov 7 at 18:12












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










You can use the :visible selector in jQuery. This will create a node list (like the querySelectorAll that will contain only the item /s that is not hidden. Then you can get the data-step value of that element.






let visibleStep =$(".step:visible");
console.log(visibleStep.attr('data-step')); // gives 1

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wathever">
<div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
<div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
<div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
</div>








share|improve this answer




























    up vote
    0
    down vote













    I just did some sketch on fiddle, try it and let me know if is what you need sir. This is a pure javascript solution.






    let nodeList = document.getElementById("wathever").querySelectorAll(".step");
    nodeList.forEach(function(div){
    if(div.style.display!="none"){
    //do something
    let dataStep = div.dataset.step;
    console.log(dataStep);
    }
    });

    <div id="wathever">
    <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
    <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
    <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
    </div>








    share|improve this answer





















      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',
      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%2f53195236%2ftake-attribute-value-from-where-style-display-is-not-none%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








      up vote
      1
      down vote



      accepted










      You can use the :visible selector in jQuery. This will create a node list (like the querySelectorAll that will contain only the item /s that is not hidden. Then you can get the data-step value of that element.






      let visibleStep =$(".step:visible");
      console.log(visibleStep.attr('data-step')); // gives 1

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <div id="wathever">
      <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
      <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
      <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
      </div>








      share|improve this answer

























        up vote
        1
        down vote



        accepted










        You can use the :visible selector in jQuery. This will create a node list (like the querySelectorAll that will contain only the item /s that is not hidden. Then you can get the data-step value of that element.






        let visibleStep =$(".step:visible");
        console.log(visibleStep.attr('data-step')); // gives 1

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <div id="wathever">
        <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
        <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
        <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
        </div>








        share|improve this answer























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You can use the :visible selector in jQuery. This will create a node list (like the querySelectorAll that will contain only the item /s that is not hidden. Then you can get the data-step value of that element.






          let visibleStep =$(".step:visible");
          console.log(visibleStep.attr('data-step')); // gives 1

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div id="wathever">
          <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
          <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
          <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
          </div>








          share|improve this answer












          You can use the :visible selector in jQuery. This will create a node list (like the querySelectorAll that will contain only the item /s that is not hidden. Then you can get the data-step value of that element.






          let visibleStep =$(".step:visible");
          console.log(visibleStep.attr('data-step')); // gives 1

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div id="wathever">
          <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
          <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
          <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
          </div>








          let visibleStep =$(".step:visible");
          console.log(visibleStep.attr('data-step')); // gives 1

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div id="wathever">
          <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
          <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
          <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
          </div>





          let visibleStep =$(".step:visible");
          console.log(visibleStep.attr('data-step')); // gives 1

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div id="wathever">
          <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
          <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
          <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
          </div>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 20:39









          gavgrif

          8,0702717




          8,0702717
























              up vote
              0
              down vote













              I just did some sketch on fiddle, try it and let me know if is what you need sir. This is a pure javascript solution.






              let nodeList = document.getElementById("wathever").querySelectorAll(".step");
              nodeList.forEach(function(div){
              if(div.style.display!="none"){
              //do something
              let dataStep = div.dataset.step;
              console.log(dataStep);
              }
              });

              <div id="wathever">
              <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
              <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
              <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
              </div>








              share|improve this answer

























                up vote
                0
                down vote













                I just did some sketch on fiddle, try it and let me know if is what you need sir. This is a pure javascript solution.






                let nodeList = document.getElementById("wathever").querySelectorAll(".step");
                nodeList.forEach(function(div){
                if(div.style.display!="none"){
                //do something
                let dataStep = div.dataset.step;
                console.log(dataStep);
                }
                });

                <div id="wathever">
                <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
                <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
                <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
                </div>








                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  I just did some sketch on fiddle, try it and let me know if is what you need sir. This is a pure javascript solution.






                  let nodeList = document.getElementById("wathever").querySelectorAll(".step");
                  nodeList.forEach(function(div){
                  if(div.style.display!="none"){
                  //do something
                  let dataStep = div.dataset.step;
                  console.log(dataStep);
                  }
                  });

                  <div id="wathever">
                  <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
                  <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
                  <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
                  </div>








                  share|improve this answer












                  I just did some sketch on fiddle, try it and let me know if is what you need sir. This is a pure javascript solution.






                  let nodeList = document.getElementById("wathever").querySelectorAll(".step");
                  nodeList.forEach(function(div){
                  if(div.style.display!="none"){
                  //do something
                  let dataStep = div.dataset.step;
                  console.log(dataStep);
                  }
                  });

                  <div id="wathever">
                  <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
                  <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
                  <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
                  </div>








                  let nodeList = document.getElementById("wathever").querySelectorAll(".step");
                  nodeList.forEach(function(div){
                  if(div.style.display!="none"){
                  //do something
                  let dataStep = div.dataset.step;
                  console.log(dataStep);
                  }
                  });

                  <div id="wathever">
                  <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
                  <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
                  <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
                  </div>





                  let nodeList = document.getElementById("wathever").querySelectorAll(".step");
                  nodeList.forEach(function(div){
                  if(div.style.display!="none"){
                  //do something
                  let dataStep = div.dataset.step;
                  console.log(dataStep);
                  }
                  });

                  <div id="wathever">
                  <div class="modal-body step step-1" data-step="1" style="display: block;">A</div>
                  <div class="modal-body step step-2" data-step="2" style="display: none;">B</div>
                  <div class="modal-body step step-3" data-step="3" style="display: none;">C</div>
                  </div>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 7 at 18:21









                  William

                  407




                  407






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195236%2ftake-attribute-value-from-where-style-display-is-not-none%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







                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini