1

i have this situation:

<div class="cont_picture">
<?php echo "<a id=\"mine_click\" href=\"#\" >a test</a>"; ?>
</div>
<div id="number"><?php echo $number; ?></div>

this will give me something like: a test 123456 (the link is as an example only)

then i have the jquery:

$('#mine_click').live('click', function() {
    var strtalentnum = $('#number').text();
    $('#mine').trigger('click');
})

and;

if($strtalentnum){
alert ($strtalentnum);
}

but the alert doesnt work.

Any ideas how to get this working? see jsfiddle

thanks

2 Answers 2

1

You have defined strtalentnum inside #mine_click click event handler and try to access it outside the handler which is out of scope. If you want to access it outside the handler then define it in the outer scope or glbally.

Also the variable you are trying to alert begins with $. I think its a typo.

Working demo

var strtalentnum;

$('#mine_click').live('click', function() {
    strtalentnum = $('#number').text();
    $('#mine').trigger('click');
});

$('#mine').click(function(){
   if(strtalentnum){
       alert (strtalentnum);
   }
}); 
Sign up to request clarification or add additional context in comments.

6 Comments

this will never trigger the alert, because when the if executes, it will always be undefined
@Shank do you not see the first comment? down voted because your original example didn't work, vengeful down voting is not very nice either...
I didnt provide any example in my original answer. I added the demo later after editing. Aslo can you tell me anywhere mentioned in the question where is if($strtalentnum){ alert ($strtalentnum); } executed? I believe it is inside $('#mine').click handler.
it's not... but that's the problem that caused him to post the question... he wan'ts it to... if you don't think he ever wants to execute it why did you edit your answer to do so?
Looking at $('#mine').trigger('click'); in the click handler made me do so.
|
1

Put the if inside the function() and beware that you are writing $strtalentnum but the variable is called strtalentnum

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.