Vzupo
Vzupo

Reputation: 1468

using jquery to alert based on condition

$( document ).ready(){

const filePath = window.top.$('#FilePath').val();
if ("#FilePath:contains('content')") {
  alert("content is here")

}

)};
<div id="filePath">content</div>

This is probably really easy but I am trying to alert a message if the filepath div contains a specific word. I looked at various setups and this was the closest I can get, please inform me on what I am doing wrong.

Upvotes: 0

Views: 410

Answers (1)

Mark Schultheiss
Mark Schultheiss

Reputation: 34168

Several errors,

$(function() {
  const filePath = $('#filePath').text();
  if (filePath.includes('content')) {
    alert("content is here");
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="filePath">content</div>

Upvotes: 1

Related Questions