I have a wordpress custom post type and i have displayed them like this
<?php
$count = 1;$counter = 1;
$query = new WP_Query( array('post_type' => 'companyhistory', 'posts_per_page' => -1, 'order' => 'ASC' ) );
while ( $query->have_posts() ) : $query->the_post();
?>
<div class="companyhistoryitem history_year<?php echo $count;?>" id="<?php echo $count;?>"><?php the_title();?></div>
<div class="company_historycontent history_year<?php echo $count;?>" id="<?php echo $counter;?>"><?php the_content();?></div>
<?php $count++;$counter++; endwhile; wp_reset_query();?>
I wanted to show corressponded content on click on the .companyhistoryitem .I am tring to connect them with this jquery code but no luck
jQuery('.companyhistoryitem').each(function(){
jQuery(this).click(function(){
var historytitleid = jQuery(this).attr('id');
jQuery('.company_historycontent').each(function(){
var historycontentid = jQuery(this).attr('id');
console.log(historycontentid);
});
var aaa = jQuery('.company_history_section .maincontainer').find('.company_historycontent').attr('id' , historytitleid);
if(historytitleid == aaa){
console.log(aaa.html());
}
});
});
TRY:
js:
Every id should be unique on the same page and it shouldn’t start with a number.
Usually in this situations I use something like:
Then: