Link to home
Start Free TrialLog in
Avatar of Sirdots
Sirdots

asked on

Search for a name in a div

I have this div in my html file. I want to be able to search for the name john bassey.
If the name is John bassey, I want  a confirm popup to come up. If the user clicks on ok it should take the user to a new page and if cancel, nothing should happen

<div class="ContentLeft">
 <h1 class="header">Employee profile - john bassey</h1>
</div>

How do I write this using jquery?
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

The jquery search
$('div.ContentLeft').has('h1.header: contains('john bassey'));
if this query has an object, then you found 'john bassey'

Check:
http://www.w3schools.com/jquery/sel_contains.asp

the confirm box code will look like:
var r=confirm("Press a button and type your mesage here");
 if (r==true)
   {
   alert("You pressed OK!");
   }
 else
   {
   alert("You pressed Cancel!");
   }
$(".ContentLeft:contains(john bassey)").css("background","green");¿
or :
$(".ContentLeft:eq(0)").filter(function() { return $(this).text().indexOf("john bassey")>=0; }).css("background","green");¿

http://jsfiddle.net/LZWRJ/1/
http://jsfiddle.net/LZWRJ/2/
dynamically :

var s = "john bassey"
//$(".ContentLeft:contains(" + s + ")").css("background","green");¿
// or 
$(".ContentLeft:eq(0)").filter(function() { return $(this).text().indexOf(s)>=0; }).css("background","green");

Open in new window

Avatar of Sirdots
Sirdots

ASKER

Thanks everyone for all your response. Here is what i want

1. search for john bassey.
2. if name john bassey is found, display a confirm popup box which says ok and cancel
3. if user clicks ok redirect to main.aspx else clear the popup box.

Am new to jquery. Am I able to store item 1 in a variable and then test if john bassey was found?
can I do a redirect to another page within jquery?
As you find an answer of your original question, please award points and close your question.
If needed create a new thread with your new question
Thanks
Avatar of Sirdots

ASKER

Thanks leakin971. My question has not been fully answered if you read the question very well.
Avatar of Sirdots

ASKER

This is not even working

var r=confirm("Press a button and type your mesage here");
 if (r==true)
   {
   alert("You pressed OK!");
   }
 else
   {
   alert("You pressed Cancel!");
   }
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sirdots

ASKER

Works like a charm. Thanks a million.
You're welcome!