shahid khan shahid khan - 1 month ago 7x
Ajax Question

getting value inside li of ajax response

i am trying to make search function i need to get value inside li which is in ajax response

my html page is

<form role="form" action="<?php echo base_url();?>comparison/selCourse" method="post" id="selAll">
<h4>Select College TO Compare </h4>
<input type="text" class="form-control" id="compFirst" name="compFirst">
<ul class="search-open" style="display: block;colour:#fff;" id="display">
<!-- End Display Drop Down For Select College -->
<!-- Begin Display Drop Down For Select Course -->
<div class="col-md-14" id="selectCourseFirst">
<h6> Select Course You Are Interested</h6>
<div class="margin-bottom-40"></div>
<!-- End Display Drop Down For Select Course -->

my jquery

$(document).ready(function() {
$("#compFirst").keypress(function() {
var option = $('#compFirst').val();
url: "http://localhost/ci/comparison/selCollege",
data: {
insId: option
type: "POST",
success: function(result) {

controller have fuction named

public function selCollege() {
$insId = htmlspecialchars($this - > input - > post('insId'));
$this - > load - > model('comparisonModel');
$selCourse = $this - > comparisonModel - > selCollege($insId);
foreach($selCourse as $key => $value) {
echo '<li>'.$value['name'].

when i try select value inside the li using jquery like

$(' li').click(function(){

i dont get any response click function doesn't work

please help


If you create html dynamically you should use something like that to detect 'click' function ;

$(document).on('click', ' li', function () {

Hope this helps.