It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet.
It's fine to use String.match()
for finding a substring but realize that String.indexOf()
is preferable if you have no need for regex: http://stackoverflow.com/a/4757501/1100355 https://stackoverflow.com/a/4757501/1100355
So you would end up with something like this:
var c = $(this).attr("class");
if (!c || c.indexOf('brush: js') < 0) {
return true;
}
...
It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet.
It's fine to use String.match()
for finding a substring but realize that String.indexOf()
is preferable if you have no need for regex: http://stackoverflow.com/a/4757501/1100355
So you would end up with something like this:
var c = $(this).attr("class");
if (!c || c.indexOf('brush: js') < 0) {
return true;
}
...
It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet.
It's fine to use String.match()
for finding a substring but realize that String.indexOf()
is preferable if you have no need for regex: https://stackoverflow.com/a/4757501/1100355
So you would end up with something like this:
var c = $(this).attr("class");
if (!c || c.indexOf('brush: js') < 0) {
return true;
}
...
It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet.
It's fine to use String.match()
for finding a substring but realize that String.indexOf()
is preferable if you have no need for regex: http://stackoverflow.com/a/4757501/1100355
So you would end up with something like this:
var c = $(this).attr("class");
if (!c || c.indexOf('brush: js') < 0) {
return true;
}
...
It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet.
It's fine to use String.match()
for finding a substring but realize that String.indexOf()
is preferable if you have no need for regex: http://stackoverflow.com/a/4757501/1100355
It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet.
It's fine to use String.match()
for finding a substring but realize that String.indexOf()
is preferable if you have no need for regex: http://stackoverflow.com/a/4757501/1100355
So you would end up with something like this:
var c = $(this).attr("class");
if (!c || c.indexOf('brush: js') < 0) {
return true;
}
...
It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet. (I'm assuming you're looking for the JS code snippets on your page so you can add a Run button for them.)
As for the actual method you're using for finding a substring, that's the correct way. If you were tryingIt's fine to match the entireuse classString.match()
value as opposed to justfor finding a substring, you would use the but realize that ===String.indexOf()
operator instead.is preferable if you have no need for regex: http://stackoverflow.com/a/4757501/1100355
It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet. (I'm assuming you're looking for the JS code snippets on your page so you can add a Run button for them.)
As for the actual method you're using for finding a substring, that's the correct way. If you were trying to match the entire class
value as opposed to just a substring, you would use the ===
operator instead.
It looks like whatever library you're using is generating properties and sticking them inside the class
attribute, which I've never seen before and seems questionable (why can't they be attributes on the element?). Because they look generated, could you maybe end up with something like this:
<pre class="class-name: 'jsbox'; brush: js">
or this:
<pre class="brush: js; [another property]; class-name: 'jsbox'">
If so, then you may want to only look for one property (like brush: js
) to determine if you're looking at a JS code snippet.
It's fine to use String.match()
for finding a substring but realize that String.indexOf()
is preferable if you have no need for regex: http://stackoverflow.com/a/4757501/1100355