I want to know if the textarea value contains a certain word. This is not working for me.
var value = $('#embedModal textarea').val();
if($(value).contains('iframe')){...
val() method is primarily used to get the values of form elements such as input , select and textarea . When called on an empty collection, it returns undefined .
jQuery :contains() SelectorThe :contains() selector selects elements containing the specified string. The string can be contained directly in the element as text, or in a child element. This is mostly used together with another selector to select the elements containing the text in a group (like in the example above).
How to find if a word or a substring is present in the given string. In this case, we will use the includes() method which determines whether a string contains the specified word or a substring. If the word or substring is present in the given string, the includes() method returns true; otherwise, it returns false.
Try javascript
if (value.indexOf('iframe') >= 0) {
JQuery contains is for DOM elements, not strings.
Try doing it like this:
$('#embedModal textarea:contains("iframe")').each(function() {
//Do something
});
edit
Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With