Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

audio or span tag not firing on Click

I have this executed html:

Image

And I am using this code to make it play the span clicked word :

precode
var pText = ['hello','my','name','is','and','i','like','food','every','day','and','every','night'];

populate(pText);

function populate(pText) {

for(var n=0; n < pText&#46;length; n++)
{
$('[name=p1_1]')&#46;append('<span id="s' + n + '"><audio id="a' + n + '" src="https:&#47;&#47;ssl&#46;gstatic&#46;com/dictionary/static/sounds/de/0/' + pText[n] +'&#46;mp3" type="audio/mpeg"></audio>' + pText[n] + '</span> ');
}
}

$("span")&#46;on("click", "#page1_p1_1", function(){
console&#46;log('test');
$(this)&#46;find('audio')[0]&#46;Play();
});

/code/pre

I am using a full page on the app which is designed under the tablet, and I am unable to see in the console.log(test), or the word 'test' in console when i click on any of the words. Is there any reason for this you can see ?

Thanks

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

audio or span tag not firing on Click

Hi Addy,

You use an event handler incorrectly.
Please check this reference: http://api.jquery.com/on/

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

audio or span tag not firing on Click

I fail to see my mistake?

Fire when a 'span' is clicked within div id 'page1_p1_1' . If it was wrongly syntax I would have received an error, which I do not.

According to your link, I have correctly used the .on event.

Please explain....

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

audio or span tag not firing on Click

Here is the code, for some reason I pasted the incorrect line above, but the code runs like this:

precode
$("&#46;page1_p1_1")&#46;on("click", "span", function() {

Code: Select all

 console&#46;log('test'); 

 $(this)&#46;find('audio')[0]&#46;Play(); 

});
/code/pre

When you click, all that happens is the footer hides. When you click again, the footer returns. Even though the footer is 'fixed' ?

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

audio or span tag not firing on Click

I changed it to 'document', means it takes a little longer, which I was trying to avoid, so it will have to do :)

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

audio or span tag not firing on Click

Hi Addy,

Please use following JS code instead of yours:

pre

$('[name="p1_1"]')&#46;append('<span id="s' + n + '" class="audioContainer"<audio id="a' + n + '" src="https:&#47;&#47;ssl&#46;gstatic&#46;com/dictionary/static/sounds/de/0/' + pText[n] +'&#46;mp3" type="audio/mpeg"</audio' + pText[n] + '</span ');

&#47;&#47;$("span")&#46;on("click", "#page1_p1_1", function(){
$("span&#46;audioContainer")&#46;on("click", function(event){
var clickedItem = jQuery(this);

Code: Select all

 var itemId = clickedItem&#46;attr("id"); 

 console&#46;log("clicked item = " + itemId); 

 if(clickedItem&#46;find('audio')[0]&#46;Play) 
  clickedItem&#46;find('audio')[0]&#46;Play(); 

});

/pre

Regards.

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

audio or span tag not firing on Click

Is there any reason why the audio would not play when compiled as a iOS app? But it works when in the browser ?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

audio or span tag not firing on Click

Hi Addy,

Please read about this issue here:

http://stackoverflow.com/questions/30...

Regads.

Return to “Issues”