Skip to content
Advertisement

jQuery get specific option tag text

All right, say I have this: What would the selector look like if I wanted to get “Option B” when I have the value ‘2’? Please note that this is not asking how to get the selected text value, but just any one of them, whether selected or not, depending on the value attribute. I tried: But it is not

How can I change an element’s class with JavaScript?

How can I change the class of an HTML element in response to an onclick or any other events using JavaScript? Answer Modern HTML5 Techniques for changing classes Modern browsers have added classList which provides methods to make it easier to manipulate classes without needing a library: Unfortunately, these do not work in Internet Explorer prior to v10, though there

Converting punycode with dash character to Unicode

I need to convert the punycode NIATO-OTABD to nñiñatoñ. I found a text converter in JavaScript the other day, but the punycode conversion doesn’t work if there’s a dash in the middle. Any suggestion to fix the “dash” issue? Answer I took the time to create the punycode below. It it based on the C code in RFC 3492. To

How to change the href attribute for a hyperlink using jQuery

How can you change the href attribute (link target) for a hyperlink using jQuery? Answer Using will modify the href of all hyperlinks to point to Google. You probably want a somewhat more refined selector though. For instance, if you have a mix of link source (hyperlink) and link target (a.k.a. “anchor”) anchor tags: …Then you probably don’t want to

How can I check if a string is a valid number?

I’m hoping there’s something in the same conceptual space as the old VB6 IsNumeric() function? Answer 2nd October 2020: note that many bare-bones approaches are fraught with subtle bugs (eg. whitespace, implicit partial parsing, radix, coercion of arrays etc.) that many of the answers here fail to take into account. The following implementation might work for you, but note that

When should I use Inline vs. External Javascript?

I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance. What is the general practice for this? Real-world-scenario – I have several html pages that need client-side form validation. For this I use a jQuery plugin that I include on all these pages.

Advertisement