this

How do I get the clicked element with inline HTML onclick and jQuery?

守給你的承諾、 提交于 2019-12-01 21:37:41
I'm creating a tags with this code: $('#td' + id).append('<p><a href="#" onclick="excluirArquivo(\'' + response + '\'); return false;"><img src="/erp/proposta/media/images/delete.png" alt="Excluir arquivo" /></a> ' + file + '</p>'); excluirArquivo function function excluirArquivo(arquivo) { $.ajax({ type: 'POST', url: '/erp/proposta/index.php/arquivo/remover/' + arquivo }); alert($(this)); } But this element inside excluirArquivo function is returning the Window object. How do I get the clicked element (a tag) inside of excluirArquivo? If you must assign your event handler that way (that is,

Toggle next element with jQuery

若如初见. 提交于 2019-12-01 21:29:52
I have a problem with the this element (I know how this is working). I have a lot of that html structure. When I click on the a button, the div with class extra-options must be shown. But since I have a lot of the same html structure repeated throughout, when I click on the button, all the other div options are also shown. How can I fix it? Here’s the JavaScript: var buttonSubmit = $(".extra-options .details a.button"); buttonSubmit.click(function (e) { e.preventDefault(); var extraOptions = $(".extra-options-tickets"); if($(".extra-options-tickets").is(":visible")) { extraOptions.hide(); }

$(this) and this inside click-event

别来无恙 提交于 2019-12-01 20:48:58
i have an own js-class and try to use jquery's $(this) and object-this in an click-event. jquery's $(this) works fine, but the object-this is not defined. http://jsfiddle.net/j33Fx/2/ var myclass = function(){ this.myfunction = function(){ alert('myfunction'); } this.buttonclicked = function(){ alert('buttonclicked'); } this.writeout = function(){ var buttoncode = '<button class="mybutton">click</button>'; $('body').append(buttoncode); $('.mybutton').click(function(){ alert('Button: '+$(this).attr('class')); this.buttonclicked(); }); this.myfunction(); } } var x = new myclass(); x.writeout();

What is the difference in the invocation of 'this' in these examples?

我的未来我决定 提交于 2019-12-01 20:37:36
I'm reading Crockford's 'JS: The Good Parts'. He has two examples using this and I don't understand why in one instance he uses this and in another he uses that . The first example: String.method('deentify', function() { var entity = { quot: '"', lt: '<', gt: '<' }; return function() { return this.replace(/&([^&;]+);/g, function (a, b) { var r = entity[b]; return typeof r === 'string' ? r : a; } ); }; }()); document.writeln('<">'.deentify()); The second example: Function.method('curry', function() { var args = arguments, that = this; return function () { return that.apply(null, args.concat

Can someone clarify Android context references?

邮差的信 提交于 2019-12-01 19:31:31
My misunderstanding continues ... Can anyone cite references for the proper use of get*Context() ? I get conflicting recommendations about using getBaseContext() , getApplicationContext() and getContext() and my understanding is that using this is a convenience to get*Context() . I would like to study more specifically of what Dalvik is intending its object and access methods. I had code reviews that changed my calls to getBaseContext() to getApplicationContext() , now I am seeing suggestions to use this. theWook http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html Read

clarification of “this” keyword in Java

让人想犯罪 __ 提交于 2019-12-01 19:15:57
I have this code copied from Android developers website: public class ExampleActivity extends Activity implements OnClickListener { protected void onCreate(Bundle savedValues) { ... Button button = (Button)findViewById(R.id.corky); button.setOnClickListener(this); } // Implement the OnClickListener callback public void onClick(View v) { // do something when the button is clicked } ... } I am wondering what exactly "this" keyword refers to? Does it refer to the class "ExampleActivity"? And in general how to find what "this" refers to? It refers to the instance of ExampleActivity on which

this is not a real pointer?

橙三吉。 提交于 2019-12-01 19:10:10
I am reading something about virtual table . When it comes to pointer __vptr , it is stated that by the author Unlike the *this pointer, which is actually a function parameter used by the compiler to resolve self-references, *__vptr is a real pointer. Consequently, it makes each class object allocated bigger by the size of one pointer. What does it mean here by saying this is actually a function parameter? And this is not a real pointer? Both pointers are real in the sense that they store an address of something else in memory. By "real" the author means "stored within the class", as opposed

clarification of “this” keyword in Java

笑着哭i 提交于 2019-12-01 18:51:59
问题 I have this code copied from Android developers website: public class ExampleActivity extends Activity implements OnClickListener { protected void onCreate(Bundle savedValues) { ... Button button = (Button)findViewById(R.id.corky); button.setOnClickListener(this); } // Implement the OnClickListener callback public void onClick(View v) { // do something when the button is clicked } ... } I am wondering what exactly "this" keyword refers to? Does it refer to the class "ExampleActivity"? And in

JavaScript closure and the this object

点点圈 提交于 2019-12-01 18:04:46
I thought I had a reasonable understanding of the this object in JavaScript. When dealing with objects, callbacks, and both events and handlers, I haven't had a problem with it since time immemorial. Now, however, all has changed. I've fallen head over heels in love with JavaScript. Pure JS, that is, not jQuery, prototype.js, dojo... So naturally, I've taken to using closures. In some cases, though, this is catching me off guard here. Take this snippet for one: function anyFunc(par) { //console.log(par); console.log(this); } function makeClosure(func) { return function(par) { return func(par);

Simple javascript to mimic jQuery behaviour of using this in events handlers

一曲冷凌霜 提交于 2019-12-01 17:59:20
This is not a question about jQuery, but about how jQuery implements such a behaviour. In jQuery you can do this: $('#some_link_id').click(function() { alert(this.tagName); //displays 'A' }) could someone explain in general terms (no need you to write code) how do they obtain to pass the event's caller html elments (a link in this specific example) into the this keyword? I obviously tried to look 1st in jQuery code, but I could not understand one line. Thanks! UPDATE: according to Anurag answer I decided to post some code at this point because it seems easier to code than what I thought: