javascript - How to access div attributes (on click event) which is inside the iframe? -
below code.
here whenever click on song1 need respective id , attributes.
<div> <iframe id="songs" src="song.html"> <div id="song1" class="sngs" name="song123">song1</div> <div id="song2" class="sngs" name="song122">song2</div> <div id="song3" class="sngs" name="song121">song3</div> </iframe> </div>
and doing here:
$(document).ready(function(){ $("iframe").click(function(){ var currentsongname=$("iframe").contents().find("#"+this.id).getattribute("name"); console.log(currentsongname); playsong(currentsongname); }); });
but here this.id coming else. how can id , attribute of div clicked on?
retrieve native element using index
var currentsongname=$("iframe").contents().find("#"+this.id)[0].getattribute("name");
or utilize jquery equivalent of attr()
var currentsongname=$("iframe").contents().find("#"+this.id).attr("name");
javascript jquery iframe
No comments:
Post a Comment