Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to select a li a based on the text using jQuery

How can I select a given li a element so that it is selected by default?

Please refer to this question to see the example that I'm working with...

How can I navigation up and down a ul using two buttons?

Basically I need to select the Patient Test li a item by default.

like image 705
Carl Weis Avatar asked Oct 19 '25 03:10

Carl Weis


2 Answers

Try this:

$(function(){
 $("#MainMenu li:contains('PATIENT TEST')").click();
});
like image 98
Chandu Avatar answered Oct 21 '25 16:10

Chandu


You could do something like this

$('li a').each(function(){
    if($(this).text() == 'PATIENT TEST'){
    //do something here
    }
});

Example: http://jsfiddle.net/jasongennaro/uuaKH/

like image 29
Jason Gennaro Avatar answered Oct 21 '25 17:10

Jason Gennaro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!