Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

javascript hide / show only works on one instance of a div.

Featured Replies

Hello, picture the scene...

 

On my website i have database blog posts echoed out.

 

They look like so:

 

<div id="blogtest">
		
		<form><input type="button" id="editbutton" class='.$editenabled.' value="Edit"></form>
            
            <div id="text">
				
				<div id="buildtext">'.$text.'</div>
				
				<div id="ckeditor">
					
				<textarea id="ckeditor" name="ckeditor" class="ckeditor">'.$text.'</textarea>
				<script type="text/javascript">
				CKEDITOR.replace( ".ckeditor" );
				</script>
				
				</div>
  
            </div>
			
        </div>

I am using this javascript code:

<script>
$(document).ready(function(){
    $("#editbutton").click(function() {        
         $('#buildtext').toggle('hide');
		 $('#ckeditor').toggle('show');
    });
});
</script>

 

Now on my test page i have 2 results that are echoed. Currently the ckeditor div is hidden via css display none.

 

If i click the edit button on my first blog output the text is hidden and the ckeditor is displayed fine.

 

However the second result doesnt work. When the edit button is pressed nothing happens.

 

Any help on this?

  • Author

Tried doing it last night but it didnt work, if i dont have the editor as hidden they both show fine.

Just the javascript button doesnt work.

Doesnt even hide the text.

  • Author

any reason why this wont work?

$(document).ready(function(){
    $(".editbutton :button").click(function () {       
         $('.buildtext',this).toggle('hide');
    });
});

it works if i say have a click function for blogtest div, but the button wont work.

 

http://jsfiddle.net/TSMcz/

Edited by Lovelock

  • Author

Once transffering a working jsfiddle to my actual page its not working.

 

The two buttons are working fine but the other divs are not showing / hiding...

 

any help?

 

here a jsfiddle

 

http://jsfiddle.net/JSX7b/

You are searching the parent of the buttons (the form) for .ckeditor and .buildtext, but they are not there.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.