How to use continue in jQuery each() loop?

We can break both a $(selector).each() loop and a $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration. return false; // this is equivalent of ‘break’ for jQuery loop return; … Read more

Is it possible to remove inline styles with jQuery?

Update: while the following solution works, there’s a much easier method. See below. Here’s what I came up with, and I hope this comes in handy – to you or anybody else: $(‘#element’).attr(‘style’, function(i, style) { return style && style.replace(/display[^;]+;?/g, ”); }); This will remove that inline style. I’m not sure this is what you … Read more

Change Twitter Bootstrap Tooltip content on click

Just found this today whilst reading the source code. So $.tooltip(string) calls any function within the Tooltip class. And if you look at Tooltip.fixTitle, it fetches the data-original-title attribute and replaces the title value with it. So we simply do: $(element).tooltip(‘hide’) .attr(‘data-original-title’, newValue) .tooltip(‘fixTitle’) .tooltip(‘show’); and sure enough, it updates the title, which is the … Read more

Access the css “:after” selector with jQuery [duplicate]

You can’t manipulate :after, because it’s not technically part of the DOM and therefore is inaccessible by any JavaScript. But you can add a new class with a new :after specified. CSS: .pageMenu .active.changed:after { /* this selector is more specific, so it takes precedence over the other :after */ border-top-width: 22px; border-left-width: 22px; border-right-width: … Read more

jQuery validate: How to add a rule for regular expression validation?

Thanks to the answer of redsquare I added a method like this: $.validator.addMethod( “regex”, function(value, element, regexp) { var re = new RegExp(regexp); return this.optional(element) || re.test(value); }, “Please check your input.” ); Now all you need to do to validate against any regex is this: $(“#Textbox”).rules(“add”, { regex: “^[a-zA-Z’.\\s]{1,40}$” }) Additionally, it looks like … Read more

Select elements by attribute

if ($(‘#A’).attr(‘myattr’)) { // attribute exists } else { // attribute does not exist } EDIT: The above will fall into the else-branch when myattr exists but is an empty string or “0”. If that’s a problem you should explicitly test on undefined: if ($(‘#A’).attr(‘myattr’) !== undefined) { // attribute exists } else { // … Read more

How do I auto-hide placeholder text upon focus using css or jquery?

Edit: All browsers support now input:focus::placeholder { color: transparent; } <input type=”text” placeholder=”Type something here!”> Firefox 15 and IE 10+ also supports this now. To expand on Casey Chu’s CSS solution: input:focus::-webkit-input-placeholder { color:transparent; } input:focus:-moz-placeholder { color:transparent; } /* FF 4-18 */ input:focus::-moz-placeholder { color:transparent; } /* FF 19+ */ input:focus:-ms-input-placeholder { color:transparent; } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)