Reputation: 49
I am testing the existence of dynamic tabs in jQuery. If it exists, select it, if not, create it.
This works 100% in FF, Chrome, etc. I am new to jQuery, so I'm struggling to make this IE 8+ compatible.
// Does the tab already exist?
var checkName = satrk;
var tabExists = false;
$('#tabs ul li a').each(function(i) {
if(this.text == checkName) {
tabExists = true;
}
});
// React to existance:
if(!tabExists){
$("#tabs").tabs("add","details.cfm?satrk="+satrk,satrk);
$("#tabs").tabs("select", satrk); // select tab by index
}else{
$("#tabs").tabs("select", satrk); // select tab by index
}
I pass the tabs index to the check.
Suggestions?
I read elsewhere that "An a element has no text property in IE." but that's not enough for me to correct my issue.
Upvotes: 0
Views: 91
Reputation: 58521
try:
if($(this).text() == checkName) {
I think in your use, this.text
is the text
property of a DOM object. If you wrap that DOM object in jQuery ($(this)
) then it should have a .text()
method that will let jQuery sort out the cross browser stuff, and just return the text you want.
Upvotes: 2