![]() This is what it looks like all done: $("button"). If it does, change it back to the original. For example, a button cannot both have a tooltip and toggle a modal. To complete the “swap”, we’ll need to compare the current text value of the button to see if it matches the swap text or not. Dont use data attributes from multiple plugins on the same element. To do that on a click event, you’d do: var button = $("button") īut that only goes one direction. primary should only be used for one button within a set. ![]() var button = $("button") īutton.data("text-original", button.text()) primary gives buttons a green outline and text, ideal for affirmation or confirmation actions. We need to store the original text first. It’s easy to swap out the text, like: var button = $("button") īut, if we did that we’d lose the orignal text forever. ![]() ![]() A data-* attribute is a perfectly good place to store the swap text. We’ll use the example of a button who’s text swaps between “Hide” and “Show”. I’d say in most cases it is a design/view concern so storing it in the markup is a good idea. if someone likes, change the text from 10 to 11. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more. You need to store the “swap” text somewhere. But I can't wrap my head around how to change the actual text value shown i.e. To call this function, pass the ID of the button element ( buttonID) and the text to put into the button. W3Schools offers free online tutorials, references and exercises in all the major languages of the web. JQuery Way (Less Markup / More JavaScript) Perhaps something simple like a “Show” button that swaps to “Hide”, or “Expand Description” to “Collapse Description.” This is a fairly simple thing to do, but there are various considerations to make. My HEXcolor script (see sig.) is another example.It’s a common need in web apps: you click something and the text of the thing you just clicked changes. Depending on what you’re trying to achieve it may be a better way to go. Using a note interface means you don’t have to reload the script. Otherwise you have to restart ZB to clear the memory.ĮDIT: an alternative way of dealing with this would be to use a note interface. I find it useful when testing code of this sort to add a temporary button to delete the memory block so that if I reload the script after changes it starts afresh. ![]() initialize code to set appropriate button text: If you want to give it a go, have a look at TVeyes’ suggestions on memory blocks in the code samples thread at the top of this forum. The main reason is that all your variables will be lost unless you write them to memory so that they are available to the script when it reloads. If you’re new to scripting then it might be best to avoid this method until you feel more confident. This is possible but you have to reload the script. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |