I am using jquery 1.10.2 and I'm having Uncaught TypeError: $(...).live is not a function. I'm using Codeigniter for development with pyrocms. Below I have written the code:-
public static function close()
{
return '</form><script>$(document).ready(function(){$("a.close").live("click", function(e){ e.preventDefault();$(this).fadeTo(200, 0);$(this).parent().fadeTo(200, 0);$(this).parent().slideUp(400, function(){$(this).remove()})})});</script>';
}
I'm new to this. Any help will be appreciated. thanks in advance.
Edit:-
From the below function I am calling the close function. please check the below code:-
public static function form($form_name, $output_array=false)
{
if ($output_array)
{
$return = self::get_fields_arrays($form_name);
$return['header'] = self::open($form_name) . $return['header'];
$return['footer'] .= self::close();
} else {
$return = self::open($form_name);
$return .= self::get_fields($form_name);
$return .= self::close();
}
self::$_ci->load->library('jquery_validation');
if ($valid = self::get_validation_array($form_name))
{
self::$_ci->jquery_validation->set_rules($valid);
if (is_array($return))
{
$return['footer'] .= self::$_ci->jquery_validation->run('#frm-'.$form_name);
}
else
{
$return .= self::$_ci->jquery_validation->run('#frm-'.$form_name);
}
}
return $return;
}
From this a tag it is getting called.
<li class="single current parent"><a href="http://php-pc/adina225.dev/hunter-valley-wine-club/wine-club-application">Wine Club Application</a></li>
Jogi Mehul please let me know if you need any more help.
I have edited the close function as Jogi suggested. So it looks like below:-
public static function close()
{
return '</form><script>$(document).ready(function(){$("a.close").on("click", function(e){ e.preventDefault();$(this).fadeTo(200, 0);$(this).parent().fadeTo(200, 0);$(this).parent().slideUp(400, function(){$(this).remove()})})});</script>';
}
now I'm having the below error:- Uncaught ReferenceError: pyroforms is not defined
private function build_script($form_name)
{
$script = '<script>$(document).ready(function() { pyroforms.init($("'.$form_name.'"), {submitHandler: function(form) { pyroforms.submit($("'.$form_name.'"), form)}, rules: %s,messages: %s});})</script>';
return sprintf($script, $this->rules, ($this->messages ? $this->messages : '{}'));
}
so the following code solved my problem.
/**
* Build jQuery validationcode
*
* @access private
* @param string
* @return string
*/
private function build_script($form_name)
{
$script = '<script>$(document).ready(function() { function pyroforms(){} pyroforms.init = function(){}; new pyroforms(); pyroforms.init($("'.$form_name.'"), {submitHandler: function(form) { pyroforms.submit($("'.$form_name.'"), form)}, rules: %s,messages: %s});})</script>';
return sprintf($script, $this->rules, ($this->messages ? $this->messages : '{}'));
}