jquery if div not id

后端 未结 5 662
孤城傲影
孤城傲影 2021-01-01 11:17

I want to cut the price off to all input value in all divs, except only one div sale_wrap. how do I make an exception with jquery?

相关标签:
5条回答
  • 2021-01-01 11:38

    Just to add little more information. One can use multiple not selector like this:

    $("div:not(#sale_wrap):not(.sale_class)");
    

    or

    $("div:not(#sale_wrap, .sale_class)");
    

    or

    $("div").not('#sale_wrap, .sale_class');
    
    0 讨论(0)
  • 2021-01-01 11:42

    The jQuery not() function can do this.

    To select all div's except the div with id of sale_wrap:

    $('div').not('#sale_wrap')
    

    You can then loop over the divs with each().

    As an example:

    #HTML
    <p id="1">Some text in paragraph 1</p>
    <p id="2">Some text in paragraph 2</p>
    <p id="3">Some text in paragraph 3</p>
    
    #JS
    # turn background to blue for all 'p' except p with id=2
    $('p').not('#2').each(function() {
        $(this).css('background-color', 'blue');
    });
    

    Check out this example on JsFiddle.

    0 讨论(0)
  • 2021-01-01 11:50

    Try using

    if($('div').not('#sale_wrap'))
    {
      t_balance;
    } 
    else
    {
      var sale = t_balance*((100-window.discount_p)/100);
      t_balance = sale;
    }
    
    0 讨论(0)
  • 2021-01-01 11:59

    Use not selector

    $("div:not(#sale_wrap)")
    
    0 讨论(0)
  • 2021-01-01 11:59

    Alternatively:

    $('div[id != "sale_wrap"]')
    
    0 讨论(0)
提交回复
热议问题