I am having problems with an Ajax script that disables my jQuery click events.
The following code works without an AJAX event:
$(document).ready(function() {
$('a.showtabinfos').click(function() {
$('div.infos').removeClass("showtab").addClass("hidetab");
$(this).parent().find('div.infos').removeClass("hidetab").addClass("showtab");
});
});
So, I found in jQuery Faq that:
http://docs.jquery.com/Frequently_Asked_Questions#Why_do_my_events_stop_working_after_an_AJAX_request.3F
But unfortunately, I'm not a JavaScript developer, and I was not able to convert my jQuery Events using event delegation. Can someone help me get my events to look like this:
$('#mydiv').click(function(e) {
if($(e.target).is('a'))
{
fn.call(e.target,e);
}
});
$('#mydiv').load('my.html');
I tried another way to solve my problem . In fact, what I'm trying to do is just open divwhen clicked by changing the class.
HTML structure:
a.showtabinfo s, , div.infos.hidetab div.infos.showtab, jQuery, JavaScript.
, :
function addClass(_element, _value)
{
try
{
var oReg = new RegExp("^([\s]*)" + _value + "$");
if(!_element.className)
{
_element.className = _value;
}
else
{
var bTest = oReg.test(_element.className);
if(bTest)
{
_element.className = _element.className.replace(_value, "");
}
else
{
var newClassName;
newClassName = _element.className;
newClassName += " ";
newClassName += _value;
_element.className = newClassName;
}
}
}
catch(e)
{
}
}
:
<a class="showtabinfos" tabindex="1" id="imagetab-<?php the_ID(); ?>" href="Javascript: ;" onclick="addClass(this.parentNode.getElementsByClassName('infos'),'showtab');">CLICK HERE</a>
- ?
, , http://www.tom-portfolio.fr/demos/portfolio/category/portfolio/, , .
<div class"infos hidetab"> to <div class="infos showtab">