Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

jQuery: Select option by inner html

Posted on 2011-05-11
4
Medium Priority
?
655 Views
Last Modified: 2012-05-11
Using jQuery, I want to select the item with the inner HTML of "Zooph"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Website</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

</head>
<body>

<h1>Using jQuery, I want to select the item with the inner text of "Zooph"</h1>

<select name="SelectMe" id="SelectMe">
<option value="" >Please Select</option>
<option value="">None</option>
<option value="">Zooph</option>
<option value="">Empty</option>
<option value="1">1</option>
<option value="3">2</option>
<option value="3">3</option>
<option value="" selected="selected">Please Select</option>
</select>

<input type="button" id="selectZooph" value="Select Zooph" />

<script type="text/javascript">
/*<![CDATA[*/


$('#selectZooph').click(function() {
  alert('Select the item Zooph');
 //$('#SelectMe').select(innerHTML='Zooph');
});

/*]]>*/
</script>

</body>
</html>

Open in new window

0
Comment
Question by:hankknight
  • 3
4 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 35743292
For example : $("#SelectMe option:contains('Zooph')").attr("selected",true);
0
 
LVL 16

Author Comment

by:hankknight
ID: 35743332
Should I first remove the selected attribute from all the other options?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 35743338
If it's a listbox (select multiple) yes else not needed
0
 
LVL 83

Expert Comment

by:leakim971
ID: 35743462
Thanks for the points!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

576 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question