I have dynamically created articles on my page within a div with an id #content. The articles have a long string of classes, for example
<article id="post-126" class="post-126 post type-post status-publish format-standard hentry category-all-portfolio category-detached portfolio_post target">
and
<article id="post-125" class="post-125 post type-post status-publish format-standard hentry category-all-portfolio category-terraced portfolio_post">
I want to add an additional class to these articles, ONLY IF it contains a certain class. For example, if the article contains the class "category-detached" (which the first one does) I want to add a class "target" to it.
Here is what I have tried, but it won't work
$(document).ready(function(){
if($('#content article').hasClass('category-detached')){
$(this).addClass('target');
}
});