如何通过其样式获取元素:左侧或右侧位置(How to get an element by its style : position left or right)

编程入门 行业动态 更新时间:2024-10-26 14:40:40
如何通过其样式获取元素:左侧或右侧位置(How to get an element by its style : position left or right)

我有这个集团,它是一个滑块元素:

<div id="sliderDispo" class="slider slider-dispo" data-slider-init="" data-slider-color="#0077b5 #EC6E31 #E40B0B" data-slider-step="33" > <div class="slider__interval"> <span>Oui</span> <span>-3mois</span> <span>-6mois</span> <span>Non</span> </div> /***** want to recuper those 2 elements <div class="ui-slider-range ui-widget-header ui-corner-all ui-slider-range-min" style="width: 0%; left: 0%;"></div> <span class="ui-slider-handle ui-state-default ui-corner-all" tabindex="0" style="left: 0%;"></span> *********/ </div>

而且我想要回收已经过评论的2个元素DIV和span

我已经开发了这个功能,我试图过滤掉具有特定风格值的元素: style =“left:0% (Div&the span)。我需要改变这些元素的风格

我的功能:

function () { var initDsiponibilite = $("#inputDisponibilite").attr("value"); alert(initDsiponibilite); $("#sliderDispo").attr("data-slider-init",initDsiponibilite); $.each( $("#sliderDispo").children().find().position.css('left','0%')) { $(this).attr("style","left:60%") }

但那没用,任何建议????

I have this bloc , it's a slider element :

<div id="sliderDispo" class="slider slider-dispo" data-slider-init="" data-slider-color="#0077b5 #EC6E31 #E40B0B" data-slider-step="33" > <div class="slider__interval"> <span>Oui</span> <span>-3mois</span> <span>-6mois</span> <span>Non</span> </div> /***** want to recuper those 2 elements <div class="ui-slider-range ui-widget-header ui-corner-all ui-slider-range-min" style="width: 0%; left: 0%;"></div> <span class="ui-slider-handle ui-state-default ui-corner-all" tabindex="0" style="left: 0%;"></span> *********/ </div>

And i wanna recuper the 2 elements DIV and span which are already prè-commented .

i have developped this fonction , where i have tried to filter out the elements which have the specific value of style : style="left: 0% (the Div & the span) . and i need that to change the style in those elements

My function:

function () { var initDsiponibilite = $("#inputDisponibilite").attr("value"); alert(initDsiponibilite); $("#sliderDispo").attr("data-slider-init",initDsiponibilite); $.each( $("#sliderDispo").children().find().position.css('left','0%')) { $(this).attr("style","left:60%") }

But that didn't work, , any suggestions ????

最满意答案

您可以尝试这样的事情:

$("#sliderDispo")
  .children()
  .filter(function(){ return $(this).css("left") === "0%"; })
  .each(function(){ $(this).css("left", "60%"); });

console.log($("div.ui-slider-range")[0].style.left); 
  
<div
  id="sliderDispo"
  class="slider slider-dispo"
  data-slider-init=""
  data-slider-color="#0077b5 #EC6E31 #E40B0B"
  data-slider-step="33">

  <div class="slider__interval">
    <span>Oui</span>
    <span>-3mois</span>
    <span>-6mois</span>
    <span>Non</span>
  </div>

  <!-- Begin: want to recuper those 2 elements -->
  <div
    class="ui-slider-range ui-widget-header ui-corner-all ui-slider-range-min"
    style="width: 0%; left: 0%;"></div>
  <span
    class="ui-slider-handle ui-state-default ui-corner-all"
    tabindex="0"
    style="left: 0%;"></span>
  <!-- End: want to recuper those 2 elements -->

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
  
 

You might try something like this:

$("#sliderDispo")
  .children()
  .filter(function(){ return $(this).css("left") === "0%"; })
  .each(function(){ $(this).css("left", "60%"); });

console.log($("div.ui-slider-range")[0].style.left); 
  
<div
  id="sliderDispo"
  class="slider slider-dispo"
  data-slider-init=""
  data-slider-color="#0077b5 #EC6E31 #E40B0B"
  data-slider-step="33">

  <div class="slider__interval">
    <span>Oui</span>
    <span>-3mois</span>
    <span>-6mois</span>
    <span>Non</span>
  </div>

  <!-- Begin: want to recuper those 2 elements -->
  <div
    class="ui-slider-range ui-widget-header ui-corner-all ui-slider-range-min"
    style="width: 0%; left: 0%;"></div>
  <span
    class="ui-slider-handle ui-state-default ui-corner-all"
    tabindex="0"
    style="left: 0%;"></span>
  <!-- End: want to recuper those 2 elements -->

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
  
 

更多推荐

本文发布于:2023-04-29 04:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335266.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   元素   位置   element   position

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!