2014-06-16 119 views
0

我已经提供了这个CSS如何动态地将一个类添加到href中?

<a href="#" class="tpActive">Butter Extra - Rs. 25/-</a> 

我一直在努力这样

$(document).on("click", ".secclass a", function (e) { 

// if(whetherchecked) 
    // { 
var name = $(this).attr("name"); 

var topping='<div class="Topping-details"><section><a href="#">'+name+'</a></section></div>'; 
//$("a").addClass("tpActive"); 
//$(this).addClass(background-color: Green!important); 
$(this).addClass("tpActive"); 
     $("#myordersdiv").append(topping); 
     clcik++; 
     $("#myordersdiv").find("i.myorderhead22").text(clcik); 
     $("#myordersdiv").show(); 
     //toppings.push(name); 
    // } 
}); 

但选定的元素不被与该类反映? 任何人都可以请帮助我?

这是完整的CSS

<div class="Topping-details"> 
<img src="images/arrow-topping.png"/> 
<section><i id="topping-close"></i> 
<a href="#">Ketchup Extra - Rs. 25/-</a> 
<a href="#" class="tpActive">Butter Extra - Rs. 25/-</a> 
<a href="#">Cheeze Extra - Rs. 25/-</a> 
</section> 
</div> 
+0

'$(this).addClass(“tpActive”);' –

+0

你想在其上添加一个“a”类。点击一个或存在于顶部变量 –

+0

点击一个。 – Pawan

回答

1
$(document).on("click", ".secclass a", function (e) { 
var name = $(this).attr("name"); 
var topping='<div class="Topping-details"><section><a href="#">'+name+'</a></section></div>'; 
$("a").each(function(){ 
    $(this).addClass("tpActive"); 
    }); 
}); 

让我知道如何去。

+0

非常感谢你。 – Pawan

+1

但它是如何正确的...它会将类添加到html中的所有“a”标签 –

相关问题