简体   繁体   中英

How do I get the div value with ajax/jquery in codeigniter?

I am using CI_Calendar custom template, I'm trying to get it so when a user clicks on the {content} a href "div class = test" on the calendar an alert will pop up with that shows what was in the div class="day_num". Ex: Monday the 1st has a link that says 'Test' on it, when I click on that link "Test' an alert will popup and say 1. As of now the alert box keeps saying undefined.

< script type = "text/javascript" >
  $(document).ready(function() {
    $('.test').click(function() {
      test= $(this).find('.test').html();
      alert(test);
    });
  }); < /script>

Given your mark up, the day_num element is actually a sibling and not a child.

The easiest way would just be to traverse backwards 1 using jQuery's .prev()

day_num = $(this).prev('.day_num').html();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM