How to get a drop down selected text from an iframe?

by ryan.murray , in category: Third Party Scripts , 4 months ago

How to get a drop down selected text from an iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dana , 4 months ago

@ryan.murray 

To get the selected text from a drop-down menu within an iframe, you can use the following jQuery code:

1
2
3
4
5
6
7
// Assuming the iframe has an id of 'myIframe'
var iframe = $('#myIframe').contents();

// Assuming the drop-down has an id of 'myDropdown'
var selectedText = iframe.find('#myDropdown').find('option:selected').text();

console.log(selectedText);


This code first selects the iframe and then finds the dropdown menu within the iframe. It then selects the currently selected option and retrieves the text content of that option. Finally, it logs the selected text to the console.


Make sure to replace 'myIframe' and 'myDropdown' with the actual ids of your iframe and drop-down menu.