Блондинка,
через toggleClass() будет проще
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
#a2{
background-color: #0000FF;
padding: 5px;
}
#b2{
background-color: #FF00FF;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function() {
$.fn.idToggle = function (arrDivId, arrSpanId) {
return this.each(function (i, el) {
$(el).click( function () {
var c = 0;
return function () {
c = ++c % arrDivId.length;
$(el).attr("id", arrDivId[c]).find("span").attr("id", arrSpanId[c])
}
}());
})
};
$("#a1").idToggle(["a1","a2"],["b1","b2"])
});
</script>
</head>
<body>
<div id="a1"><span id="b1">text one</span></div>
</body>
</html>