How can I hide a string and replace it with a view/hide button using jQuery?

If you have control of the output of the page then the best way to do it is just to create a div or span or similar which is what you want to hide span id="editsTode">These are my edits'; var dynamicText = messageText. Substring(staticText. Length-1); var newHTML = staticText + ''+dynamicText+'' $('.

Note_message'). Html(newHTML) You can see it finds the contents of your "note_message" span (note if there is more than one of these unexpected behaviour may occur). It then chops off the known part to get the unknown part (you may want to do some validation to make sure the bit you chop off was actually what you expected in case of changes to outputted HTML).

It then constructs some new HTML with a span to give it the format as described above and then continue as before Hope this helps Edit 2: Just updated the second jsfiddle since I realised I wasn't dynamically adding the button.

If you have control of the output of the page then the best way to do it is just to create a div or span or similar which is what you want to hide. These are my edits And then you can find this easily with $('#EditsTonet/8q8ds/ is an example of the code you want (probably could be done more stylishly and more neatly but its a proof of concept that shoudl get you thinking in the right direction. Note I also added in stuff to make it work on non-JS browsers by having CSS hide the button and not the edits and then teh javascript hides the edits and shows the buttons.No JS means it will show the data always rather than have it hidden with no way to get to it.

:) Edit: To do it without control of the markup you need to add in your own markup. I've done a new fiddle based on the old one here: jsfiddle.net/8q8ds/2/.The key new code is: var messageText = $('. Note_message').html() var staticText = 'The order was manually edited:'; var dynamicText = messageText.

Substring(staticText. Length-1); var newHTML = staticText + ''+dynamicText+'' $('. Note_message').

Html(newHTML); You can see it finds the contents of your "note_message" span (note if there is more than one of these unexpected behaviour may occur). It then chops off the known part to get the unknown part (you may want to do some validation to make sure the bit you chop off was actually what you expected in case of changes to outputted HTML). It then constructs some new HTML with a span to give it the format as described above and then continue as before.

Hope this helps. Edit 2: Just updated the second jsfiddle since I realised I wasn't dynamically adding the button.

Your code looks really good, except, I don't have control of the string I am using. That is why I want to select all of the text after the string "The order was manually edited:" and save that into a variable. How can I do that first?

– zeckdude Jul 16 '10 at 10:19 @zeckdude: In that case we need to see more of your page structure. The information you've given us might allow us to find where to start looking for the string to show/hide but we've currently got no info on how we'd find the end of that string. Show us the HTML around this section of page and we might be able to help you find a way of locating what you want.

– Chris Jul 16 '10 at 10:39 The order was manually edited:The list of edits goes here, and this maybe somewhat long sometimes That is an example of the html structure of what the string is in. It is always the same class and it always starts with that string. – zeckdude Jul 16 '10 at 10:42 @zeckdude: I've edited my answer to include how to cope with needing to alter the initial markup.

I hope this helps you a bit but make sure you code defensively against changes to the HTML format so you don't end up just butchering the page if it changes. – Chris Jul 16 '10 at 11:26.

Then just hide it using javascript so people without it can enjoy your list of edits too. Some sample code: The order was manually edited: Some edits.

If you have control of the output of the page then the best way to do it is just to create a div or span or similar which is what you want to hide. http://jsfiddle.net/8q8ds/ is an example of the code you want (probably could be done more stylishly and more neatly but its a proof of concept that shoudl get you thinking in the right direction. Note I also added in stuff to make it work on non-JS browsers by having CSS hide the button and not the edits and then teh javascript hides the edits and shows the buttons.

No JS means it will show the data always rather than have it hidden with no way to get to it. To do it without control of the markup you need to add in your own markup.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions