mitrich38,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.test {
color:red;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(function(){
$('p:contains("text1")', $('.my').parents(".main_class")).addClass('test');
})
</script>
</head>
<body>
<div class="main_class" id="1">
<div class="cont" id="1-1">
<p>text1</p>
<p>text1</p>
<p>text1</p>
<p>text1</p>
<p>text1</p>
<p>text1</p>
</div>
<div class="size_fixed" id="1-2"></div>
<div class="my"></div>
</div>
<div class="main_class" id="2">
<div class="cont" id="2-1">
<p>text1</p>
<p>text1</p>
<p>text1</p>
<p>text1</p>
<p>text1</p>
<p>text1</p>
</div>
<div class="size_fixed" id="2-2"></div>
<div class="my_2"></div>
</div>
</body>
</html>