How To Get The Span Id Which Starts With A Word
actually i have two span with ids like this date_eform and time_eform. Now i have to get these ids.. and check if the span id starts with date_ then i have to perform some logic. a
Solution 1:
you need starts with selector
so
$.each('span[id^="date_"]',function(){
//your code here
});
and
$.each('span[id^="time_"]',function(){
//your code here
});
Solution 2:
Try this:
$("span[id^='date_']").something...
$("span[id^='time_']").something-else...
Solution 3:
This should work:
$("span[id^={word}]")
Where {word} is the word you want the element id to start with.
The following like will help: http://api.jquery.com/attribute-starts-with-selector/
Solution 4:
this should do it:
$('[id^="date_"]')
Solution 5:
jQuery syntax for attribute ends with:
$('span[id$="_eform"]')
jQuery syntax for attribute starts with:
$('span[id^="_eform"]')
jQuery syntax for attribute contains:
$('span[id*="_eform"]')
From what I understand, you should need to do something like:
$('span[id$="_eform"]')
Then, with an each
method, test if jQuery-object ids are date
or time
.
var elements = $('span[id$="_eform"]');
elements.each(function() {
if(this.id.substring(0,5)=='date') {
// handle dates
} else if(this.id.substring(0,5)=='time_') {
// handle times
}
});
Post a Comment for "How To Get The Span Id Which Starts With A Word"