Javascript jQuery:如何从我的 div 中删除 css 边框属性?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12624570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 10:52:39  来源:igfitidea点击:

jQuery: How do I remove a css border property from my div?

javascriptjquerycss

提问by daveomcd

I'm trying to remove the border of a div, but no luck. I've commented out the code in my css and it is the correct property that I want to remove. Here is the code I'm using currently. The background-color change is working that's in the code below but the removeClass is not.

我正在尝试删除 div 的边框,但没有运气。我已经注释掉了我的 css 中的代码,它是我想要删除的正确属性。这是我目前使用的代码。背景颜色更改在下面的代码中起作用,但 removeClass 不是。

var tab = getURLParameter("tab");

// Disable the visual style of the button since it is disabled for this page.
if (tab == "Property") {
    $(".scrape-button").css('background-color', '#efefef');
    $(".scrape-button:hover").removeClass('border');
}

Any ideas? Thanks!

有任何想法吗?谢谢!

回答by Adriano Carneiro

Just remove the css property like this:

只需像这样删除 css 属性:

$(".scrape-button:hover").css('border','');

.removeClass()is used for removing a declared css class from element.

.removeClass()用于从元素中删除声明的 css 类。

回答by coolxeo

The jQuery selector with hover pseudo class has no effect because there is no element in the page with hover state. I recommend you to try a different aproach

带有悬停伪类的 jQuery 选择器不起作用,因为页面中没有具有悬停状态的元素。我建议您尝试不同的方法

<script>
  var tab = getURLParameter("tab");

  if (tab == "Property") {
    $(".scrape-button").addClass("disabled")
  }
</script>
<style>
  .disabled {
    background-color: #EFEFEF;
  }

  .disabled:hover {
    border: none;
  }
</style>

回答by SNAG

$('.scrape-button:hover').css('border', 'none');

Try this

尝试这个

回答by Sushanth --

There is no :hoverpseudo class in jQuery..

jQuery 中没有:hover伪类。

Try this

尝试这个

$('.scrape-button').hover(function() {
    $(this).removeClass('border')
}, function() {
    $(this).addClass('border')
});?

Check FIDDLE?

检查小提琴

回答by Vijay Verma

Please try if you are using class--

如果您正在使用类,请尝试-

$(".scrape-button:hover").attr('class','');

回答by C47

Try this:

尝试这个:

$(".scrape-button:hover").css('border','');

or

或者

$('.scrape-button:hover').css('border', 'none');