Conditional replacement element-wise
I would use MapIndexed[]
+ KroneckerDelta[]
for this:
MapIndexed[# /. jj -> Apply[KroneckerDelta, #2] &, A, {2}]
{{2 AcD am g1, 1, 3 + g}, {2 g1, g1, AcD}, {0, g1, AcD + am}}
This works by extracting the Diagonal from the matrix first, setting jj in the diagonal to 1 and adding it again to the matrix, where all jj's have been set to zero:
A = {{2 AcD am g1 jj, jj + 1, 3 + g}, {jj + 2 g1, g1 jj,
AcD + jj}, {jj g1, g1 + jj, AcD + jj*am}}
setDiagonalEntries[m_?MatrixQ] :=
With[{d = Diagonal[m] //. jj -> 1,
o = (m - DiagonalMatrix[Diagonal[m]]) //. jj -> 0},
DiagonalMatrix[d] + o]
setDiagonalEntries[A] // MatrixForm