I have this piece of jquery/javascript and i don't understand why this is happend and how should i fixed it. The tag with the id="group_"+num is loaded with ajax so it seem not being added to the DOM yet , the funny part is if i put one alert in the middle the function works, without that alert nothing happend , ¿ anyone could explain what alert does there and what should i do to get that id in the DOM so jquery could count the length as 1 ? Of course if i get any other id not loaded with ajax , works.
$(document).ready(function(){
$(function() {
var hash = window.location.hash;
var num = hash.replace("#subcat_group_","");
$('[id*="subcat_group_"]').hide();
// here the "id" loaded with ajax seems still not loaded.
var len = $("#group_"+num).length;
//Here variable "len" still 0
/***** with this alert works , just an alert anything inside
alert(num);
with this alert works *****/
/*******if i use "len" here still 0 even if alert is before *******/
if( $("#group_"+num).length === 1){
/******if i get again for id lenght with alert before , then is 1 ******/
if( $("#group_"+num).length === 1){
var group_name = $("#group_"+num).attr("title");
swapContentV1(num,group_name);
}
$("#subcat_group_"+num).show();
});
});
thanks.