Solved

jquery toggle two elements

Posted on 2011-09-20
13
304 Views
Last Modified: 2012-05-12
Im trying to toggle 2 elements :

when I just toggle one its worked any idea?



 function toggleLeadBody(id) {
              var fieldname1 = "spam_"+ id + "_body";
                    var fieldName2 = "sr_" + id + "_body";
                    var element = $('#' + fieldName1, '#' +fieldName2);
                    element.toggle();
            }


<tr style="border-style: solid; border-width: 1px;">
        <td colspan="5"
            style="color: blue; display: none; padding: 0px 25px 0px 25px;"
            id="sr_{$row['id']}_body"
        >
            Subject: {$row['subject']}<br />
            {$message}
		<td colspan="5"
            style="color: red; padding: 0px 25px 0px 25px;"
		    id="spam_{$row['id']}_body"
			>
			Mark as spam
    </tr>

Open in new window

0
Comment
Question by:Nura111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
13 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36568702
try with

var element = $('#' + fieldName1 +  ', #' +fieldName2);
0
 

Author Comment

by:Nura111
ID: 36568866
it doesnt work
when I used    function toggleLeadBody(id) {
                    var fieldName = "sr_" + id + "_body";
                    var element = $('#' + fieldName);
                    element.toggle();
            }

for one elemet before it was ok
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 500 total points
ID: 36568883
try
 function toggleLeadBody(id) {
              var fieldname1 = "#spam_"+ id + "_body";
                    var fieldName2 = "#sr_" + id + "_body";
                    var element = $(fieldName1 +  ', ' + fieldName2);
                    element.toggle();
            }


0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 82

Expert Comment

by:leakim971
ID: 36568886
may help : http://jsfiddle.net/9UFge/

<span>Select a State</span>
<select>
    <option value="">Select a State</option>
    <option value="AL">Alabama</option>
    <option value="CA">California</option>
</select>

Open in new window


    $("span").click(function() {
        $("select").css("display","block");
    })
    $("select").change(function() {
        $("span").html( $("option:selected",this).text() );
        $("select").css("display","none");
    }) 

Open in new window

0
 

Author Comment

by:Nura111
ID: 36568918
no its not working :

function toggleLeadBody(id) {
                              var fieldname1 = "#spam_"+ id + "_body";
                    var fieldName2 = "#sr_" + id + "_body";
                    var element = $(fieldName1 + ',' + fieldName2);

                    element.toggle();
                            //element = $('#'+ fieldName2);
                              //element.toggle();

            }
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36568947
i guess it has to be done separately only, one by one

0
 

Author Comment

by:Nura111
ID: 36568984
yes I tried that also its not working as well:
  function toggleLeadBody(id) {
                              var fieldname1 = "#spam_"+ id + "_body";
                    var fieldName2 = "#sr_" + id + "_body";
                    var element2 = $(fieldName2);
                              element2.toggle();
                              var element1 = $(fieldName1);

                    element1.toggle();
                            //element = $('#'+ fieldName2);
                              //element.toggle();


}


maybe the problrm is in the html?? I cant see any problem but I attached it before to the question as a code
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36569000
when you say, it doesn't work what do you mean?

also, how are these two elements related to each other?
0
 

Author Comment

by:Nura111
ID: 36569009
its mean that its not showing the elements  when clicking on the event the starting  toggleLeadBody() function.
0
 

Author Comment

by:Nura111
ID: 36569012
the two element need to show together when clicking
0
 

Author Comment

by:Nura111
ID: 36569096
sorry to trouble you in a stupid mistake the   var fieldname1 was with small letter. that was it..
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36569098
ID:36568886 (bad thread, sorry)
0
 

Author Closing Comment

by:Nura111
ID: 36569681
The main one worked as well but this is other suggestion..
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question