0

I am trying to check with JQuery if a Div #id has a certain character or not.

Here's the code I'm trying:

if ($("#mydiv").html('0')) { alert'zero character was found'; } 

The alert is not popping up.

I'm I doing it wrong?

1
  • Your title says check div HTML but your question says div ID. Which one is it? Commented Mar 25, 2014 at 13:21

4 Answers 4

2
if ($("#mydiv:contains(0)")) { alert('zero character was found'); // do not forget also `(` } 
Sign up to request clarification or add additional context in comments.

Comments

2

try using contains

$("#mydiv:contains(0)") 

Comments

1

If I read your question correctly and you're looking for a div whose id contains the string 0 then this should work for you:

 if ($("div[id*='0']").length>0) { alert('zero character was found'); } 

http://jsfiddle.net/mT862/

Comments

0

try using native javascript

var str = $("#mydiv").text(); if (str.indexOf('0') !== -1) { alert('zero character was found'); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.