Reputation: 1381
I have an IP managing script with ranges and jquery search to check if IP is already used, I add class to each row for the IPs for that range, like this
<tr class="table_176 213.5.176.120 213.5.176.121 213.5.176.122 213.5.176.123 213.5.176.124" id="213.5.176.120-124" style="display:none;">
<td class="actualip" align="center" >213.5.176.120-124</td>
<td >5</td>
<td colspan="2" align="center" ><a href="https://www.racksrv.com/portal/staff/clientssummary.php?userid=637" target="_blank"> Mike Burkett</a></td>
<td align="center" ><a href="https://www.racksrv.com/portal/staff/clientshosting.php?userid=637&id=1537">RS96</a></td>
<td ></td>
<td align="center" ><a href="https://www.racksrv.com/portal/staff/supporttickets.php?action=open&userid=637" target="_blank"><img src="https://www.racksrv.com/portal/staff/images/icons/ticketsopen.png" alt="Open Ticket for " title="Open Ticket for " width="16" height="16"/></a></td>
</tr>
And use the following JQ
$('#search').click(function() {
$found = false;
$ip = $('#value').val();
if ( $("."+$ip).length ){
alert("found");
}
if($found == false) {
alert('The IP you searched for was not found!');
}
});
But this isn't working? Anyone got any ideas?
Upvotes: 0
Views: 898
Reputation: 1381
my own mistake was answered by
"$('.213.5.176.120') <=> class="213 5 176 120" Dots in classnames should be avoided (or escaped in the jQ selector) "
Upvotes: 0
Reputation: 1221
As everyone else has said, the problem is your class. It's easy to simply replace those dots with underscores and use those in your class name. Here's a quick and dirty example: http://jsfiddle.net/LFfwZ/
Upvotes: 0
Reputation: 24236
As the comments suggest your problem is being caused by the dots in your class names, if you have to store the IP addresses in a class name then something like this would work -
var ip = '213.5.176.120';
if ($("tr[class*='" + ip + "']").length){
alert("found");
}
Demo - http://jsfiddle.net/eZCdf/
Upvotes: 1
Reputation: 47624
First, I'm pretty sure that dot (.) are not valid in class name, and even if they are, I wouldn't use them. That's confusing. By the way, according to the specs, class couldn't begin with a number.
All CSS syntax is case-insensitive within the ASCII range (i.e., [a-z] and [A-Z] are equivalent), except for parts that are not under the control of CSS. For example, the case-sensitivity of values of the HTML attributes "id" and "class", of font names, and of URIs lies outside the scope of this specification. Note in particular that element names are case-insensitive in HTML, but case-sensitive in XML. In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".
Check the CSS Syntax
Second, you shouldn't use class to store metadata, jQuery provides a convenient method to do that, and it's simply called, data()
.
Keep the classes for what they deserve, CSS.
Upvotes: 0