jquery - Cannot read property 'substring' of undefined after putting the line in setTimeout -


i checked console in browser carefully.
line:

document.getelementbyid("role_show_" + $(this).attr("id").substring(7, 9)).style.display = "block"; 

is executed normally. when put in settimeout this:

settimeout(function() {     document.getelementbyid("role_show_" + $(this).attr("id").substring(7, 9)).style.display = "block"; }, 400); 

the console displays error:
uncaught typeerror: cannot read property 'substring' of undefined

what going on here? sure other lines of code unedited.

settimeout function made $(this) in different scope want be. make work, save $(this) variable before call settimeout function.

var = $(this); settimeout(function() {     document.getelementbyid("role_show_" + $(this).attr("id").substring(7, 9)).style.display = "block"; }, 400); 

so can access $(this) in settimeout function using that basically.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -