1

I have something like this...

$().ready(function () {

    $(".post .comment_this").click(function () {

        var comment_id = $(this).attr('rel');

        $.post(url_base + 'bio/community/get_comments', { 'comment_id' : comment_id }, function (response) {

            console.log(comment_id);

        });

    });

});

How to pass comment_id into that function? So I can use it there...

kapa
  • 77,694
  • 21
  • 158
  • 175
daGrevis
  • 21,014
  • 37
  • 100
  • 139

2 Answers2

4

You can use it there without a problem.

In Javascript you can access every variable defined in the scope chain, up to the global scope. Locally defined variables will override the ones that come from the chain.

JavaScript Variable Scope on SO

Community
  • 1
  • 1
kapa
  • 77,694
  • 21
  • 158
  • 175
0

Should be fine:

<button id="go">Go!</button>
<div id="TestDiv">dd</div>

$("#go").live('click', function(e) {
    alert("win");
    var TestVar = "Message :)";
    $("#TestDiv").load("http://www.ryth.net/", function () {
        alert(TestVar);
    });
});

http://jsfiddle.net/EDx3A/1/

Kev
  • 118,037
  • 53
  • 300
  • 385
Henry
  • 2,187
  • 1
  • 15
  • 28