0

Is there a way to group div IDs that are scared across multiple pages but get to be called to the same page at some point with Jquery.

I want to hide or show all the divs in a group while showing only a certain group. The reason some group gets to be included in other functions and writing all the list of this many div IDs is somehow not wise.

2nd question. How do I program a button to reload page and then after run a function with jquery?

ok let me add some code to make sense of this reload problem.

$('#accountresult').click();
location.reload();  //Should reload page 1st and then function
$('#button').show("slow");
$("#Atresult").load("source_cxchange.html #account");
$("#result, #homeresult, #appleresult" ).empty()
});

but rather, it only runs reload and dies, someone please correct the syntax of putting two functions to successively follow one another.

Blessing Thinker
  • 261
  • 1
  • 4
  • 14

2 Answers2

0

My advice would be to group them using a class rather than a collection of ids. That way you can target them all at once with:

$('.someClass').hide() 

As for reloading the page and running a function afterwards that gets a bit trickier can you explain what you are trying to achieve?

When you refresh the page you lose the javascript callstack so you will have to set a querystring or use cookies/local storage to persist a value. You can then use jQuery's onLoad() function to run your function only if the url parameter or cookie exists.

JanR
  • 6,052
  • 3
  • 23
  • 30
  • This button loads divs from external pages, so I want those divs to find a clean page. Problem being that if the button concerned is not clicked first, other divs would be loaded on the page and when that div comes, they are just there all of them, I don't want anything on the page except that very div at that moment. – Blessing Thinker Jun 25 '13 at 06:57
  • Can you maybe show the function for the button or show some markup to make sense of this? – JanR Jun 25 '13 at 07:24
0

1) Assign some class to those ids and use $('.someclass') to refer them.

2) To reload page, you will need to call 'location.reload();'. then you can do whatever you should in $(function() {});, which is called whenever page is loaded.

David Jashi
  • 4,490
  • 1
  • 21
  • 26