Reputation: 10775
I am facing a problem that I want to remove all child elements border of a container div using jQuery.
Child elements can be image, div, p tag, or anchor or any HTML tag.
Here's my try:
$(document).ready(function (){
$("#div1").children("div").css("border","0px solid red");
});
Upvotes: 1
Views: 3697
Reputation: 1399
for all children it will be
$("#div1").children().css("border", "0");
But if you add the borders by the style attribute like you did before you could also go for
$("#div1").children().removeAttr("style");
Hope this helps
Upvotes: 0
Reputation: 444
Well, that's easy:
$("#div1 *").css({
border: "none"
});
Or if you have a jquery-object of your parent:
var $div = $("#div1");
$div.find("*").css({
border: "none"
});
If you know that you just want to remove borders from div-elements instead of all elements inside, just use:
var $div = $("#div1");
$div.find("div").css({
border: "none"
});
Upvotes: 0
Reputation: 2522
Change children to find, like this.
$(document).ready(function (){
$("#div1").find("*").css("border", "0");
});
And here's the fiddle: http://jsfiddle.net/Yu25h/
Upvotes: 6