Ram
Posts: 0
Joined: Fri Aug 02, 2013 12:15 pm

$(this) in JS asset function

Dear Appery,

i have a few html div's images inside an HTML widget:

code
<div class="btn food objects">
<img src="files&#47;views&#47;assets&#47;image&#47;g&#46;jpg" alt="image" onClick=playThis('exampl1')>
<&#47;div>

Code: Select all

 <div class="btn food"> 
     <img src="files&#47;views&#47;assets&#47;image&#47;h&#46;jpg" alt="image" onClick=playThis('exampl2')> 
 <&#47;div>    

/code

and a function in an outside JS asset:

code
function playThis (val) {
alert(val);
$(this)&#46;hide();
}
/code

although i get the correct val when clicking on each img but i dont get to hide the img...

what am i missing here?

Many thanks in advance!
Best,
R.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

$(this) in JS asset function

Hi Ram,

Your code is not working for me, can you provide more details how you make it?

Ram
Posts: 0
Joined: Fri Aug 02, 2013 12:15 pm

$(this) in JS asset function

Hi Illya,

i sent to support public link, thx much!

btw - only this button calls the function:

Image

thx again!

Ram
Posts: 0
Joined: Fri Aug 02, 2013 12:15 pm

$(this) in JS asset function

never mind, got it to work, thx.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

$(this) in JS asset function

Hi Ram, thanks for update. Glad it's working!

Can you share how you solved this issue? It might be helpful for someone.

Ram
Posts: 0
Joined: Fri Aug 02, 2013 12:15 pm

$(this) in JS asset function

what i did was using the ID instead of $(this) :

in the html widget i have many div's like this
code
<div class="btn food objects">
<img id="first" src="files&#47;views&#47;assets&#47;image&#47;g&#46;jpg" alt="image" onClick='playThis("first","exampl1")'>
<&#47;div>
/code

and in the JS asset file:
code
function playThis (id, image) {
$("#"+id)&#46;attr('src', image);
}
/code

Best,
R.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

$(this) in JS asset function

Thank you for sharing.

Return to “Issues”